generated from pkg/go-template
fix : brahma api 中间件的修复
parent
be9aac681f
commit
6267dc56f2
|
@ -8,6 +8,7 @@ import (
|
|||
"git.icechen.cn/monorepo/backend/app/brahma/api/murder/internal/handler"
|
||||
"git.icechen.cn/monorepo/backend/pkg/api"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/gofiber/fiber/v2/middleware/recover"
|
||||
"github.com/gofiber/fiber/v2/middleware/requestid"
|
||||
ctxLogger "github.com/luizsuper/ctxLoggers"
|
||||
"go.uber.org/zap"
|
||||
|
@ -22,11 +23,8 @@ const (
|
|||
|
||||
var (
|
||||
err error
|
||||
//Init App
|
||||
app = fiber.New(fiber.Config{
|
||||
ErrorHandler: func(ctx *fiber.Ctx, err error) error {
|
||||
return ctx.Status(fiber.StatusInternalServerError).JSON(handler.Response{Message: "服务器内部错误"})
|
||||
},
|
||||
ErrorHandler: api.FiberMiddleWareErrHandler,
|
||||
})
|
||||
)
|
||||
|
||||
|
@ -49,12 +47,10 @@ func ResourceInit() {
|
|||
}
|
||||
|
||||
func appInit() {
|
||||
//requestId
|
||||
app.Use(requestid.New())
|
||||
//recover
|
||||
app.Use(api.FibberMiddleWareRecoverHandler)
|
||||
//requestId for gorm
|
||||
app.Use(api.FibberUserCtxWithTraceHandler)
|
||||
app.Use(api.FibberMiddleWareRespHandler)
|
||||
app.Use(recover.New(api.GetFibberRecoverConfig()))
|
||||
}
|
||||
|
||||
func routerInit() {
|
||||
|
|
|
@ -50,9 +50,9 @@ func FibberMiddleWareRespHandler(c *fiber.Ctx) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// FibberMiddleWareRecoverHandler fiberPanicRecover
|
||||
func FibberMiddleWareRecoverHandler() fiber.Handler {
|
||||
return recover.New(recover.Config{
|
||||
// GetFibberRecoverConfig fiberPanicRecoverConfig
|
||||
func GetFibberRecoverConfig() recover.Config {
|
||||
return recover.Config{
|
||||
EnableStackTrace: true,
|
||||
StackTraceHandler: func(c *fiber.Ctx, e interface{}) {
|
||||
buf := make([]byte, 1024*1024)
|
||||
|
@ -60,7 +60,7 @@ func FibberMiddleWareRecoverHandler() fiber.Handler {
|
|||
fmt.Printf("panic: %v\n%s\n", e, buf)
|
||||
ctxLogger.FError(c, "panic", zap.String("", fmt.Sprintf("panic: %v\n%s\n", e, buf)))
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// FibberUserCtxWithTraceHandler 把fibberCtx的traceId 置入UserCtx中
|
||||
|
|
Loading…
Reference in New Issue