Thinking > guide
Go Http Client guide

Always set a sane value for timeouts when using http.Client

When initializing a HTTP Client generally people use

client := &http.Client{}

However, this allows someone to hijack your goroutines. Look at this simple example:

svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

When you use


Your client will hang for an hour and then terminate. In order to remedy this always specify a sane timeout:

client := &http.Client{ Timeout: time.second * 10 }

Reference: Don't use Go's default HTTP client (in production)

Recent Posts

Let's talk.

Give Us a Call
(800) 352-2292
Business Inquiries