Skip to content

Instantly share code, notes, and snippets.

@farhany
Last active April 18, 2019 20:00
Show Gist options
  • Save farhany/70a6557908c13e7d1b8e96eaad29560a to your computer and use it in GitHub Desktop.
Save farhany/70a6557908c13e7d1b8e96eaad29560a to your computer and use it in GitHub Desktop.
Increase http timeout
// Source: https://www.reddit.com/r/golang/comments/45mzie/dont_use_gos_default_http_client/
// Go Source: https://golang.org/pkg/net/http/#Client
// Timeout specifies a time limit for requests made by this
// Client. The timeout includes connection time, any
// redirects, and reading the response body. The timer remains
// running after Get, Head, Post, or Do return and will
// interrupt reading of the Response.Body.
//
// A Timeout of zero means no timeout.
//
// The Client's Transport must support the CancelRequest
// method or Client will return errors when attempting to make
// a request with Get, Head, Post, or Do. Client's default
// Transport (DefaultTransport) supports CancelRequest.
func main() {
http.DefaultClient.Timeout = 10 * time.Second
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment