From 69b0fb05aa25649a16964feb32b3c7ee72a4fd80 Mon Sep 17 00:00:00 2001 From: bryanqiu Date: Sun, 4 Feb 2024 15:29:11 +0800 Subject: [PATCH] add AlreadyHaveResult function --- context.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/context.go b/context.go index 0959b9f..a4a3cf2 100644 --- a/context.go +++ b/context.go @@ -120,7 +120,14 @@ func (c *Context) SetCookie(cookie *http.Cookie) { http.SetCookie(c.Writer, cookie) } +func (c *Context) AlreadyHaveResult() (done bool, entry string) { + return c.resultentry == "", c.resultentry +} + func (c *Context) RESULT(output interface{}) error { + if c.resultentry == "" { + c.resultentry = "RESULT" + } var t = reflect.TypeOf(output) defer func(o *interface{}) { b, err := json.Marshal(o) @@ -149,7 +156,6 @@ func (c *Context) RESULT(output interface{}) error { cost := time.Now().Sub(c.starttime).Milliseconds() noticeStr := fmt.Sprintf("cost: %dms, output: '%s'", cost, string(b)) log.NoticefWithDepth(calldepth, noticeStr) - }(&output) if _, ok := t.FieldByName("ErrCode"); !ok {