Canonical guidance

Use when

Avoid

Preferred pattern

func handler(w http.ResponseWriter, r *http.Request) {
	defer func() {
		if rec := recover(); rec != nil {
			http.Error(w, "internal error", http.StatusInternalServerError)
		}
	}()
	serve(w, r)
}

Anti-pattern

if err != nil {
	panic(err)
}

Explanation: This anti-pattern is tempting because panic is concise, but expected failures deserve explicit control flow and caller-visible error handling.

Why

Sources