Canonical guidance

Use when

Avoid

Preferred pattern

req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
if err != nil {
	return err
}
resp, err := client.Do(req)
if err != nil {
	return err
}
defer resp.Body.Close()

Anti-pattern

Explanation: This anti-pattern is tempting in small helpers, but ad hoc clients and missing body cleanup quietly waste connections and increase latency.

Why

Related pages

Sources