Forgetting the return after replying to an HTTP request
Mistake
func handler(w http.ResponseWriter, req *http.Request) {
err := foo(req)
if err != nil {
// this doesn't stop the function
http.Error(w, "foo", http.StatusInternalServerError)
}
// ...
}
Fix
func handler(w http.ResponseWriter, req *http.Request) {
err := foo(req)
if err != nil {
http.Error(w, "foo", http.StatusInternalServerError)
return
}
// ...
}