January 2019
Beginner
132 pages
3h 14m
English
Inside the $GOPATH/src folder that you set up, create a folder called simplerequest. Inside simplerequest, create a file called main.go. Set the contents of main.go to be the following code:
package mainimport ( "log" "net/http" "os")func main() { // Create the variables for the response and error var r *http.Response var err error // Request index.html from example.com r, err = http.Get("http://www.example.com/index.html") // If there is a problem accessing the server, kill the program and print the error the console if err != nil { panic(err) } // Check the status code returned by the server if r.StatusCode == 200 { // The request was successful! var webPageContent []byte // We know the size of the response is 1270 ...Read now
Unlock full access