100-go-mistakes/10-standard-lib/80-http-return/main.go
2021-12-27 15:56:17 +01:00

28 lines
542 B
Go

package main
import "net/http"
func handler1(w http.ResponseWriter, req *http.Request) {
err := foo(req)
if err != nil {
http.Error(w, "foo", http.StatusInternalServerError)
}
_, _ = w.Write([]byte("all good"))
w.WriteHeader(http.StatusCreated)
}
func handler2(w http.ResponseWriter, req *http.Request) {
err := foo(req)
if err != nil {
http.Error(w, "foo", http.StatusInternalServerError)
return
}
_, _ = w.Write([]byte("all good"))
w.WriteHeader(http.StatusCreated)
}
func foo(req *http.Request) error {
return nil
}