dual check v0.1
This commit is contained in:
1 parent
78bad1fa3d
commit
c137299016
36 files changed
+3727
-81
No files matched your search
@@ -0,0 +1,22 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
// Recover 捕获 panic 并返回 500
|
||||
func Recover(logger *zap.Logger) gin.HandlerFunc {
|
||||
return gin.CustomRecovery(func(c *gin.Context, err interface{}) {
|
||||
logger.Error("panic recovered",
|
||||
zap.Any("error", err),
|
||||
zap.String("path", c.Request.URL.Path),
|
||||
zap.String("request_id", c.GetString("request_id")),
|
||||
)
|
||||
c.JSON(500, gin.H{
|
||||
"code": 5000,
|
||||
"message": "internal server error",
|
||||
})
|
||||
c.Abort()
|
||||
})
|
||||
}
|
||||
Reference in new issue
Block a user