Skip to content

Instantly share code, notes, and snippets.

@DQNEO
Created November 16, 2018 05:15
Show Gist options
  • Select an option

  • Save DQNEO/bd7de2f884da2a7b1a1cd013e184a9ba to your computer and use it in GitHub Desktop.

Select an option

Save DQNEO/bd7de2f884da2a7b1a1cd013e184a9ba to your computer and use it in GitHub Desktop.
Go httpclient sample code
package main
import (
"fmt"
"io/ioutil"
"log"
"net/http"
)
func main() {
get()
}
func get() {
client := &http.Client{}
res, err := client.Get("https://httpbin.org/get?foo=1&bar=2")
if err != nil {
log.Fatal(err)
}
text, err := ioutil.ReadAll(res.Body)
res.Body.Close()
if err != nil {
log.Fatal(err)
}
fmt.Printf("%s", text)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment