From dcf076a185f21b38f139eeabee5c39e4d937238e Mon Sep 17 00:00:00 2001 From: Acexy Date: Fri, 31 May 2024 11:43:45 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=90=AF=E5=8A=A8=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=8C=85=E8=A3=B9=E5=BC=82=E5=B8=B8=E5=93=8D=E5=BA=94=E7=A0=81?= =?UTF-8?q?=E5=90=8E=E6=9C=AA=E8=83=BD=E6=AD=A3=E5=B8=B8=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ginmodule/ginloader.go | 1 - ginmodule/middleware.go | 20 ++++++++++---------- ginmodule/router.go | 2 +- go.mod | 4 ++-- go.sum | 2 ++ test/ginstarter_test.go | 2 +- 6 files changed, 16 insertions(+), 15 deletions(-) diff --git a/ginmodule/ginloader.go b/ginmodule/ginloader.go index 0b5ac3e..a237894 100644 --- a/ginmodule/ginloader.go +++ b/ginmodule/ginloader.go @@ -65,7 +65,6 @@ func (g *GinModule) Register() (interface{}, error) { gin.DefaultWriter = &logrusLogger{log: logger.Logrus(), level: logrus.DebugLevel} gin.DefaultErrorWriter = &logrusLogger{log: logger.Logrus(), level: logrus.ErrorLevel} - ginEngin := gin.New() if g.MaxMultipartMemory > 0 { diff --git a/ginmodule/middleware.go b/ginmodule/middleware.go index adb295e..eabce12 100644 --- a/ginmodule/middleware.go +++ b/ginmodule/middleware.go @@ -22,17 +22,17 @@ func init() { func ErrorCodeHandler() gin.HandlerFunc { return func(ctx *gin.Context) { ctx.Next() - if !ctx.IsAborted() { - statusCode := ctx.Writer.Status() - if statusCode != http.StatusOK { - logger.Logrus().Warnln("not success response statusCode =", statusCode) - v, ok := httpCodeWithStatus[statusCode] - if !ok { - ctx.AbortWithStatusJSON(http.StatusOK, ResponseException()) - } else { - ctx.AbortWithStatusJSON(http.StatusOK, ResponseError(v)) - } + statusCode := ctx.Writer.Status() + if statusCode != http.StatusOK { + ctx.Status(200) + logger.Logrus().Warnln("not success response statusCode =", statusCode) + v, ok := httpCodeWithStatus[statusCode] + if !ok { + ctx.AbortWithStatusJSON(http.StatusOK, ResponseException()) + } else { + ctx.AbortWithStatusJSON(http.StatusOK, ResponseError(v)) } + ctx.Abort() } } } diff --git a/ginmodule/router.go b/ginmodule/router.go index d7712e3..2646bc0 100644 --- a/ginmodule/router.go +++ b/ginmodule/router.go @@ -13,7 +13,7 @@ type HandlerWrapper func(request *Request) (*Response, error) type RouterInfo struct { GroupPath string - // 如果指定基于BasicAuth认证的账户,则该GroupPath下资源将需要权限认证 如果不满足验证规则,则会返回相应的httpStatus错误码,并且不会被本框架包装 + // 如果指定基于BasicAuth认证的账户,则该GroupPath下资源将需要权限认证 BasicAuthAccount map[string]string } diff --git a/go.mod b/go.mod index 8fd132d..a4b5830 100644 --- a/go.mod +++ b/go.mod @@ -6,10 +6,11 @@ require ( github.com/acexy/golang-toolkit v0.0.9 github.com/gin-gonic/gin v1.10.0 github.com/golang-acexy/starter-parent v0.0.6 + github.com/sirupsen/logrus v1.9.3 ) require ( - github.com/bytedance/sonic v1.11.7 // indirect + github.com/bytedance/sonic v1.11.8 // indirect github.com/bytedance/sonic/loader v0.1.1 // indirect github.com/cloudwego/base64x v0.1.4 // indirect github.com/cloudwego/iasm v0.2.0 // indirect @@ -26,7 +27,6 @@ require ( github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect github.com/pelletier/go-toml/v2 v2.2.2 // indirect - github.com/sirupsen/logrus v1.9.3 // indirect github.com/twitchyliquid64/golang-asm v0.15.1 // indirect github.com/ugorji/go/codec v1.2.12 // indirect golang.org/x/arch v0.8.0 // indirect diff --git a/go.sum b/go.sum index 331bcea..f215a0e 100644 --- a/go.sum +++ b/go.sum @@ -8,6 +8,8 @@ github.com/bytedance/sonic v1.11.6 h1:oUp34TzMlL+OY1OUWxHqsdkgC/Zfc85zGqw9siXjrc github.com/bytedance/sonic v1.11.6/go.mod h1:LysEHSvpvDySVdC2f87zGWf6CIKJcAvqab1ZaiQtds4= github.com/bytedance/sonic v1.11.7 h1:k/l9p1hZpNIMJSk37wL9ltkcpqLfIho1vYthi4xT2t4= github.com/bytedance/sonic v1.11.7/go.mod h1:LysEHSvpvDySVdC2f87zGWf6CIKJcAvqab1ZaiQtds4= +github.com/bytedance/sonic v1.11.8 h1:Zw/j1KfiS+OYTi9lyB3bb0CFxPJVkM17k1wyDG32LRA= +github.com/bytedance/sonic v1.11.8/go.mod h1:LysEHSvpvDySVdC2f87zGWf6CIKJcAvqab1ZaiQtds4= github.com/bytedance/sonic/loader v0.1.1 h1:c+e5Pt1k/cy5wMveRDyk2X4B9hF4g7an8N3zCYjJFNM= github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU= github.com/cloudwego/base64x v0.1.4 h1:jwCgWpFanWmN8xoIUHa2rtzmkd5J2plF/dnLS6Xd/0Y= diff --git a/test/ginstarter_test.go b/test/ginstarter_test.go index 9f70109..38dd4fd 100644 --- a/test/ginstarter_test.go +++ b/test/ginstarter_test.go @@ -23,7 +23,7 @@ func init() { moduleLoaders = []declaration.ModuleLoader{&ginmodule.GinModule{ ListenAddress: ":8080", - DebugModule: true, + DebugModule: false, UseErrorCodeHandler: true, Routers: []ginmodule.Router{ &router.DemoRouter{},