mirror of
https://github.com/teivah/100-go-mistakes.git
synced 2026-06-20 16:45:56 +08:00
28 lines
542 B
Go
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
|
|
}
|