generated from pkg/go-template
@@ -1,20 +1,17 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"git.icechen.cn/monorepo/backend/app/brahma/api/murder/internal/config"
|
||||
"git.icechen.cn/monorepo/backend/app/brahma/api/murder/internal/error_process"
|
||||
"git.icechen.cn/monorepo/backend/app/brahma/api/murder/internal/gorm_helper"
|
||||
"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/logger"
|
||||
"github.com/gofiber/fiber/v2/middleware/recover"
|
||||
"github.com/gofiber/fiber/v2/middleware/requestid"
|
||||
ctxLogger "github.com/luizsuper/ctxLoggers"
|
||||
"go.uber.org/zap"
|
||||
"os"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -54,25 +51,10 @@ func ResourceInit() {
|
||||
func appInit() {
|
||||
//requestId
|
||||
app.Use(requestid.New())
|
||||
//logger
|
||||
app.Use(logger.New(logger.Config{
|
||||
Format: "${respHeader:X-Request-ID} ${status} - ${method} ${path} ${resBody}\n",
|
||||
}))
|
||||
//recover
|
||||
app.Use(recover.New(recover.Config{
|
||||
EnableStackTrace: true,
|
||||
StackTraceHandler: func(c *fiber.Ctx, e interface{}) {
|
||||
buf := make([]byte, 1024*1024)
|
||||
buf = buf[:runtime.Stack(buf, false)]
|
||||
fmt.Printf("panic: %v\n%s\n", e, buf)
|
||||
ctxLogger.FError(c, error_process.PanicError, zap.String("", fmt.Sprintf("panic: %v\n%s\n", e, buf)))
|
||||
},
|
||||
}))
|
||||
app.Use(api.FibberRecover)
|
||||
//requestId for gorm
|
||||
app.Use(func(ctx *fiber.Ctx) error {
|
||||
ctx.SetUserContext(context.WithValue(context.Background(), fiber.HeaderXRequestID, ctx.Response().Header.Peek(fiber.HeaderXRequestID)))
|
||||
return ctx.Next()
|
||||
})
|
||||
app.Use(api.FibberUserCtxWithTrace)
|
||||
}
|
||||
|
||||
func routerInit() {
|
||||
|
||||
Reference in New Issue
Block a user