From 7ded01de44bc79ea9e47f0625c9edb71c4a092ee Mon Sep 17 00:00:00 2001 From: 17361943071 <5446203+aisleeppppp@user.noreply.gitee.com> Date: Fri, 26 Nov 2021 15:01:45 +0800 Subject: [PATCH 1/3] =?UTF-8?q?handler=20err=20=E5=A4=84=E7=90=86,?= =?UTF-8?q?=E4=B8=8D=E7=84=B6commit=E4=B8=8D=E4=BA=86...?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gee-cache/day3-http-server/geecache/http.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/gee-cache/day3-http-server/geecache/http.go b/gee-cache/day3-http-server/geecache/http.go index b9b994e..5437610 100644 --- a/gee-cache/day3-http-server/geecache/http.go +++ b/gee-cache/day3-http-server/geecache/http.go @@ -58,5 +58,8 @@ func (p *HTTPPool) ServeHTTP(w http.ResponseWriter, r *http.Request) { } w.Header().Set("Content-Type", "application/octet-stream") - w.Write(view.ByteSlice()) + _, err = w.Write(view.ByteSlice()) + if err != nil { + return + } } From ca8cde6fb57c96967b9529b6ccdddf96fb09f7d1 Mon Sep 17 00:00:00 2001 From: 17361943071 <5446203+aisleeppppp@user.noreply.gitee.com> Date: Tue, 7 Dec 2021 14:45:10 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9Context=E4=B8=AD=E7=9A=84?= =?UTF-8?q?JSON=20Encode=20err=E7=9A=84=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gee-web/day2-context/gee/context.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gee-web/day2-context/gee/context.go b/gee-web/day2-context/gee/context.go index 72a7fe7..c2537fb 100644 --- a/gee-web/day2-context/gee/context.go +++ b/gee-web/day2-context/gee/context.go @@ -56,8 +56,9 @@ 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) + panic(err) } + return } func (c *Context) Data(code int, data []byte) { From 40aea4bf61aa17ada6ec4666fcef956e7a7efa11 Mon Sep 17 00:00:00 2001 From: 17361943071 <5446203+aisleeppppp@user.noreply.gitee.com> Date: Thu, 9 Dec 2021 10:59:24 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9Context=E7=9A=84Fail?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gee-web/day5-middleware/gee/context.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/gee-web/day5-middleware/gee/context.go b/gee-web/day5-middleware/gee/context.go index 1885e0c..5fb87b5 100644 --- a/gee-web/day5-middleware/gee/context.go +++ b/gee-web/day5-middleware/gee/context.go @@ -42,8 +42,10 @@ func (c *Context) Next() { } func (c *Context) Fail(code int, err string) { - c.index = len(c.handlers) - c.JSON(code, H{"message": err}) + if c == nil { + c.index = len(c.handlers) + c.JSON(code, H{"message": err}) + } } func (c *Context) Param(key string) string {