1
0
mirror of https://github.com/golang/go synced 2024-11-11 22:10:22 -07:00

Modify HTTP status codes to variables

This commit is contained in:
unknown 2018-02-26 13:16:19 +09:00
parent 39852bf4cc
commit c1c90bcd25
3 changed files with 5 additions and 5 deletions

View File

@ -20,11 +20,11 @@ func viewRecord(w http.ResponseWriter, r *http.Request) {
key := datastore.NewKey(c, "Record", r.FormValue("id"), 0, nil)
record := new(Record)
if err := datastore.Get(c, key, record); err != nil {
http.Error(w, err.Error(), 500)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
if err := viewTemplate.Execute(w, record); err != nil {
http.Error(w, err.Error(), 500)
http.Error(w, err.Error(), http.StatusInternalServerError)
}
}

View File

@ -33,7 +33,7 @@ type appHandler func(http.ResponseWriter, *http.Request) error
func (fn appHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if err := fn(w, r); err != nil {
http.Error(w, err.Error(), 500)
http.Error(w, err.Error(), http.StatusInternalServerError)
}
}

View File

@ -107,7 +107,7 @@ func DateServer(rw http.ResponseWriter, req *http.Request) {
date, err := exec.Command("/bin/date").Output()
if err != nil {
http.Error(rw, err.Error(), 500)
http.Error(rw, err.Error(), http.StatusInternalServerError)
return
}
rw.Write(date)
@ -115,7 +115,7 @@ func DateServer(rw http.ResponseWriter, req *http.Request) {
func Logger(w http.ResponseWriter, req *http.Request) {
log.Print(req.URL)
http.Error(w, "oops", 404)
http.Error(w, "oops", http.StatusNotFound)
}
var webroot = flag.String("root", os.Getenv("HOME"), "web root directory")