]> Cypherpunks repositories - gostls13.git/commitdiff
net/http,doc: use HTTP status code constants where applicable
authorunknown <geon0250@gmail.com>
Mon, 26 Feb 2018 04:41:20 +0000 (04:41 +0000)
committerAndrew Bonventre <andybons@golang.org>
Mon, 26 Feb 2018 05:04:31 +0000 (05:04 +0000)
There are a few places where the integer value is used.
Use the equivalent constants to aid with readability.

Change-Id: I023b1dbe605340544c056d0e0d9d6d5a7d7d0edc
GitHub-Last-Rev: c1c90bcd251901f9f2a305ce5ddd0d85009a3d49
GitHub-Pull-Request: golang/go#24123
Reviewed-on: https://go-review.googlesource.com/96984
Reviewed-by: Andrew Bonventre <andybons@golang.org>
doc/progs/error2.go
doc/progs/error3.go
src/net/http/triv.go

index 2b0e0c3563a56d4738ec6deadcb850e2490624a1..086b6710d360aa38218e73204dbb5696cf6d5628 100644 (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)
        }
 }
 
index e4e57e077b52ace4126868985272fe060e5d9b5d..d9e56b5d64e472730023f6f5f0e012a1673ad58e 100644 (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)
        }
 }
 
index cfbc5778c1cc499097a3362e4dca3b350dd664cb..23e65d56e86f5ae83633620a879250d52a57f6bd 100644 (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")