From 35095b18aaea64ca2f5555965ed8e8a0a2c609a1 Mon Sep 17 00:00:00 2001 From: lvhuat Date: Wed, 13 Mar 2019 14:32:46 +0800 Subject: [PATCH 1/2] add constomized Report --- service/restful/wrap/report.go | 10 ++++++++++ service/restful/wrap/wrapper.go | 6 +++++- 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 service/restful/wrap/report.go diff --git a/service/restful/wrap/report.go b/service/restful/wrap/report.go new file mode 100644 index 0000000..a2a3681 --- /dev/null +++ b/service/restful/wrap/report.go @@ -0,0 +1,10 @@ +package wrap + +import ( + "time" + + "github.com/gin-gonic/gin" + "github.com/lworkltd/kits/service/restful/code" +) + +var Report func(err code.Error, ctx *gin.Context, status int, since time.Time) diff --git a/service/restful/wrap/wrapper.go b/service/restful/wrap/wrapper.go index e63563b..f310f28 100644 --- a/service/restful/wrap/wrapper.go +++ b/service/restful/wrap/wrapper.go @@ -14,12 +14,12 @@ import ( "io" "strings" - "github.com/Sirupsen/logrus" "github.com/gin-gonic/gin" "github.com/lworkltd/kits/service/context" "github.com/lworkltd/kits/service/monitor" "github.com/lworkltd/kits/service/restful/code" logutils "github.com/lworkltd/kits/utils/log" + "github.com/sirupsen/logrus" ) var ( @@ -254,6 +254,10 @@ func (wrapper *Wrapper) Wrap(f WrappedFunc, registPath string) gin.HandlerFunc { httpCtx.JSON(http.StatusOK, resp) } + if Report != nil { + Report(cerr, httpCtx, http.StatusOK, since) + } + if cerr != nil { l.WithFields(logrus.Fields{ "message": cerr.Message(), From e33fd1166c7c8d278bf0ee162ea3f68796319377 Mon Sep 17 00:00:00 2001 From: lvhuat Date: Wed, 13 Mar 2019 14:34:33 +0800 Subject: [PATCH 2/2] fix Sirupsen --- service/restful/wrap/wrapper.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/service/restful/wrap/wrapper.go b/service/restful/wrap/wrapper.go index f310f28..f2615eb 100644 --- a/service/restful/wrap/wrapper.go +++ b/service/restful/wrap/wrapper.go @@ -14,12 +14,12 @@ import ( "io" "strings" + "github.com/Sirupsen/logrus" "github.com/gin-gonic/gin" "github.com/lworkltd/kits/service/context" "github.com/lworkltd/kits/service/monitor" "github.com/lworkltd/kits/service/restful/code" logutils "github.com/lworkltd/kits/utils/log" - "github.com/sirupsen/logrus" ) var (