From 19b8fd044ca82c2cf1e6b7af891250caeba173d3 Mon Sep 17 00:00:00 2001 From: jxlwqq Date: Wed, 25 Aug 2021 14:29:51 +0800 Subject: [PATCH 1/2] Update context.go --- gee-web/day2-context/gee/context.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gee-web/day2-context/gee/context.go b/gee-web/day2-context/gee/context.go index 72a7fe7..7b124e4 100644 --- a/gee-web/day2-context/gee/context.go +++ b/gee-web/day2-context/gee/context.go @@ -56,7 +56,7 @@ func (c *Context) JSON(code int, obj interface{}) { c.Status(code) encoder := json.NewEncoder(c.Writer) if err := encoder.Encode(obj); err != nil { - http.Error(c.Writer, err.Error(), 500) + http.Error(c.Writer, err.Error(), http.StatusInternalServerError) } } From 599ba07d1e15b69e21d2f405f6d6b41784fcaf02 Mon Sep 17 00:00:00 2001 From: jxlwqq Date: Wed, 25 Aug 2021 15:42:11 +0800 Subject: [PATCH 2/2] replace 500 with http.StatusInternalServerError --- gee-web/README.md | 2 +- gee-web/day3-router/gee/context.go | 2 +- gee-web/day4-group/gee/context.go | 2 +- gee-web/day5-middleware/gee/context.go | 2 +- gee-web/day5-middleware/main.go | 2 +- gee-web/day6-template/gee/context.go | 4 ++-- gee-web/day7-panic-recover/gee/context.go | 4 ++-- gee-web/doc/gee-day2.md | 4 ++-- gee-web/doc/gee-day5.md | 2 +- gee-web/doc/gee-day6.md | 2 +- 10 files changed, 13 insertions(+), 13 deletions(-) diff --git a/gee-web/README.md b/gee-web/README.md index d56ed8d..6b6685c 100644 --- a/gee-web/README.md +++ b/gee-web/README.md @@ -134,7 +134,7 @@ func onlyForV2() gee.HandlerFunc { // Start timer t := time.Now() // if a server error occurred - c.Fail(500, "Internal Server Error") + c.Fail(http.StatusInternalServerError, "Internal Server Error") // Calculate resolution time log.Printf("[%d] %s in %v for group v2", c.StatusCode, c.Req.RequestURI, time.Since(t)) } diff --git a/gee-web/day3-router/gee/context.go b/gee-web/day3-router/gee/context.go index cf79939..cf244e7 100644 --- a/gee-web/day3-router/gee/context.go +++ b/gee-web/day3-router/gee/context.go @@ -62,7 +62,7 @@ func (c *Context) JSON(code int, obj interface{}) { c.Status(code) encoder := json.NewEncoder(c.Writer) if err := encoder.Encode(obj); err != nil { - http.Error(c.Writer, err.Error(), 500) + http.Error(c.Writer, err.Error(), http.StatusInternalServerError) } } diff --git a/gee-web/day4-group/gee/context.go b/gee-web/day4-group/gee/context.go index cf79939..cf244e7 100644 --- a/gee-web/day4-group/gee/context.go +++ b/gee-web/day4-group/gee/context.go @@ -62,7 +62,7 @@ func (c *Context) JSON(code int, obj interface{}) { c.Status(code) encoder := json.NewEncoder(c.Writer) if err := encoder.Encode(obj); err != nil { - http.Error(c.Writer, err.Error(), 500) + http.Error(c.Writer, err.Error(), http.StatusInternalServerError) } } diff --git a/gee-web/day5-middleware/gee/context.go b/gee-web/day5-middleware/gee/context.go index 1885e0c..71cd75a 100644 --- a/gee-web/day5-middleware/gee/context.go +++ b/gee-web/day5-middleware/gee/context.go @@ -79,7 +79,7 @@ func (c *Context) JSON(code int, obj interface{}) { c.Status(code) encoder := json.NewEncoder(c.Writer) if err := encoder.Encode(obj); err != nil { - http.Error(c.Writer, err.Error(), 500) + http.Error(c.Writer, err.Error(), http.StatusInternalServerError) } } diff --git a/gee-web/day5-middleware/main.go b/gee-web/day5-middleware/main.go index b66dbdc..027ff99 100644 --- a/gee-web/day5-middleware/main.go +++ b/gee-web/day5-middleware/main.go @@ -32,7 +32,7 @@ func onlyForV2() gee.HandlerFunc { // Start timer t := time.Now() // if a server error occurred - c.Fail(500, "Internal Server Error") + c.Fail(http.StatusInternalServerError, "Internal Server Error") // Calculate resolution time log.Printf("[%d] %s in %v for group v2", c.StatusCode, c.Req.RequestURI, time.Since(t)) } diff --git a/gee-web/day6-template/gee/context.go b/gee-web/day6-template/gee/context.go index 9c47b0c..2b8e2c9 100644 --- a/gee-web/day6-template/gee/context.go +++ b/gee-web/day6-template/gee/context.go @@ -81,7 +81,7 @@ func (c *Context) JSON(code int, obj interface{}) { c.Status(code) encoder := json.NewEncoder(c.Writer) if err := encoder.Encode(obj); err != nil { - http.Error(c.Writer, err.Error(), 500) + http.Error(c.Writer, err.Error(), http.StatusInternalServerError) } } @@ -96,6 +96,6 @@ func (c *Context) HTML(code int, name string, data interface{}) { c.SetHeader("Content-Type", "text/html") c.Status(code) if err := c.engine.htmlTemplates.ExecuteTemplate(c.Writer, name, data); err != nil { - c.Fail(500, err.Error()) + c.Fail(http.StatusInternalServerError, err.Error()) } } diff --git a/gee-web/day7-panic-recover/gee/context.go b/gee-web/day7-panic-recover/gee/context.go index 9c47b0c..2b8e2c9 100644 --- a/gee-web/day7-panic-recover/gee/context.go +++ b/gee-web/day7-panic-recover/gee/context.go @@ -81,7 +81,7 @@ func (c *Context) JSON(code int, obj interface{}) { c.Status(code) encoder := json.NewEncoder(c.Writer) if err := encoder.Encode(obj); err != nil { - http.Error(c.Writer, err.Error(), 500) + http.Error(c.Writer, err.Error(), http.StatusInternalServerError) } } @@ -96,6 +96,6 @@ func (c *Context) HTML(code int, name string, data interface{}) { c.SetHeader("Content-Type", "text/html") c.Status(code) if err := c.engine.htmlTemplates.ExecuteTemplate(c.Writer, name, data); err != nil { - c.Fail(500, err.Error()) + c.Fail(http.StatusInternalServerError, err.Error()) } } diff --git a/gee-web/doc/gee-day2.md b/gee-web/doc/gee-day2.md index 9bd011f..bba8c84 100644 --- a/gee-web/doc/gee-day2.md +++ b/gee-web/doc/gee-day2.md @@ -75,7 +75,7 @@ w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusOK) encoder := json.NewEncoder(w) if err := encoder.Encode(obj); err != nil { - http.Error(w, err.Error(), 500) + http.Error(w, err.Error(), http.StatusInternalServerError) } ``` @@ -146,7 +146,7 @@ func (c *Context) JSON(code int, obj interface{}) { c.Status(code) encoder := json.NewEncoder(c.Writer) if err := encoder.Encode(obj); err != nil { - http.Error(c.Writer, err.Error(), 500) + http.Error(c.Writer, err.Error(), http.StatusInternalServerError) } } diff --git a/gee-web/doc/gee-day5.md b/gee-web/doc/gee-day5.md index 7a540a1..269f817 100644 --- a/gee-web/doc/gee-day5.md +++ b/gee-web/doc/gee-day5.md @@ -185,7 +185,7 @@ func onlyForV2() gee.HandlerFunc { // Start timer t := time.Now() // if a server error occurred - c.Fail(500, "Internal Server Error") + c.Fail(http.StatusInternalServerError, "Internal Server Error") // Calculate resolution time log.Printf("[%d] %s in %v for group v2", c.StatusCode, c.Req.RequestURI, time.Since(t)) } diff --git a/gee-web/doc/gee-day6.md b/gee-web/doc/gee-day6.md index 1a6283a..23c69ed 100644 --- a/gee-web/doc/gee-day6.md +++ b/gee-web/doc/gee-day6.md @@ -119,7 +119,7 @@ func (c *Context) HTML(code int, name string, data interface{}) { c.SetHeader("Content-Type", "text/html") c.Status(code) if err := c.engine.htmlTemplates.ExecuteTemplate(c.Writer, name, data); err != nil { - c.Fail(500, err.Error()) + c.Fail(http.StatusInternalServerError, err.Error()) } } ```