Skip to content

Commit

Permalink
Merge pull request #9 from golang-acexy/develop
Browse files Browse the repository at this point in the history
fix: 启动自动包裹异常响应码后未能正常处理
  • Loading branch information
acexy authored May 31, 2024
2 parents 0b9b4b7 + dcf076a commit 89afa06
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 15 deletions.
1 change: 0 additions & 1 deletion ginmodule/ginloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
20 changes: 10 additions & 10 deletions ginmodule/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion ginmodule/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
2 changes: 1 addition & 1 deletion test/ginstarter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func init() {

moduleLoaders = []declaration.ModuleLoader{&ginmodule.GinModule{
ListenAddress: ":8080",
DebugModule: true,
DebugModule: false,
UseErrorCodeHandler: true,
Routers: []ginmodule.Router{
&router.DemoRouter{},
Expand Down

0 comments on commit 89afa06

Please sign in to comment.