ETA 6.14.2022. For future readers - the culprit is my antivirus, as it works when I turn it off. I'll have to make an exception in the av. Thanks to those who took time to read, comment or research this!
I'm new to Go, and I'd appreciate some help with running some simple looking Code.... (on Windows however :-) )
This code does not work
package main
import (
"fmt"
"net/http"
)
func main() {
fmt.Println("Hello World")
response, err := http.Get("https://www.google.com/robots.txt")
if err != nil {
panic(err)
}
response.Body.Close()
if err != nil {
panic(err)
}
fmt.Println("Goodbye World")
}
By "not working" I mean that it simply exits with no output and no error, and brings up a new prompt line (no hanging, just acts like it ran a program with no output and completed)
This code does work:
package main
import (
"fmt"
)
func main() {
fmt.Println("Hello World")
fmt.Println("Goodbye World")
}
You'll see the expected Hello and Goodbye.
I'm running this on VS Code, using Integrated Terminal.
I've also run similar code outside VS Code in Cmd Prompt and Powershell.
I'm on Windows 10.
Appreciate any suggestions!
P.S. I do realize that some people argue that running Go on Windows is acting for trouble. But if anyone has information on how to get this apparently simple code to run on Windows, I'd appreciate it.
ETA. Thanks for the responses!
Points to clarify:
I am aware I'm not printing anything from the response itself. At the moment I'm just trying to get the plain Hello And Goodbye statements to co-exist with the Get call and print out.
I appreciate the confirmation that this code should compile and run on Windows. Any ideas on what I should look for in my environment would be appreciated!