Perform a basic GET request and prints the contents of a site (HTML).
package main
import (
"fmt"
"io/ioutil"
"net/http"
)
func main() {
resp, err := http.Get("https://example.com/")
if err != nil {
panic(err)
}
// It is important to defer resp.Body.Close(), else resource leaks will occur.
defer resp.Body.Close()
data, err := ioutil.ReadAll(resp.Body)
if err != nil {
panic(err)
}
// Will print site contents (HTML) to output
fmt.Println(string(data))
}