Golang net/http.Client.Get() function example

package net/http

Golang net/http.Client.Get() function usage example

 package main

 import (
 "fmt"
 "io/ioutil"
 "net/http"
 "os"
 )

 func main() {

 client := &http.Client{}

 resp, err := client.Get("https://golang.org")

 if err != nil {
 fmt.Println(err)
 os.Exit(1)
 }

 defer resp.Body.Close()

 htmlData, err := ioutil.ReadAll(resp.Body)

 if err != nil {
 fmt.Println(err)
 os.Exit(1)
 }

 fmt.Println(os.Stdout, string(htmlData))

 }

See also : https://www.socketloop.com/tutorials/golang-http-get-example

Reference :

http://golang.org/pkg/net/http/#Client.Get

Advertisement