Making HTTP requests is a core part of many applications these days. Go, being a web-friendly language, contains several tools for making HTTP requests in the net/http package.
HTTP client
The basic HTTP request
This example uses the http.Get() function from the net/http standard library package. It will read the entire response body to a variable named body and then print it to standard output:
package main
import (
"fmt"
"io/ioutil"
"log"
"net/http"
)
func main() {
// Make basic HTTP GET request
response, err := http.Get("http://www.example.com")
if err != nil {
log.Fatal("Error fetching URL. ", err)
}
// Read body from response
body, err ...