Don’t use Go’s default HTTP client (in production)

// error checking omitted for brevity
var sprockets SprocketsResponse
response, _ := http.Get("")
buf, _ := ioutil.ReadAll(response.Body)
json.Unmarshal(buf, &sprockets)
var DefaultClient = &Client{}
package mainimport (
func main() {
svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
defer svr.Close()
fmt.Println(“making request”)
fmt.Println(“finished request”)
var netClient = &http.Client{
Timeout: time.Second * 10,
response, _ := netClient.Get(url)
err: err.Error() + " (Client.Timeout exceeded while awaiting headers)",
timeout: true,
var netTransport = &http.Transport{
Dial: (&net.Dialer{
Timeout: 5 * time.Second,
TLSHandshakeTimeout: 5 * time.Second,
var netClient = &http.Client{
Timeout: time.Second * 10,
Transport: netTransport,
response, _ := netClient.Get(url)



Software engineer, CTO of HER Social App. Social justice matters and you should care about it.

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store