Connection pooling in Go

Go handles connection pooling automatically via http.Transport, allowing you to configure reuse limits and timeouts for better performance.

Go manages connection pooling automatically via the http.Transport type, which caches idle connections for reuse. To configure pool behavior, instantiate a Transport with specific limits like MaxIdleConns and MaxIdleConnsPerHost, then assign it to your http.Client.

client := &http.Client{
	Transport: &http.Transport{
		MaxIdleConns:        100,
		MaxIdleConnsPerHost: 2,
		IdleConnTimeout:     90 * time.Second,
	},
}

If you need to disable connection reuse entirely, set DisableKeepAlives to true in the Transport configuration.