feat: 增加全局 panic 捕获的中间件

This commit is contained in:
2026-01-04 11:44:23 +08:00
parent 85f2008997
commit 330f7c880d
3 changed files with 40 additions and 0 deletions

View File

@@ -115,6 +115,8 @@ type server struct {
func (s *server) getGlobalMiddlewareList(option *serverOption) []gin.HandlerFunc {
globalMiddlewareList := make([]gin.HandlerFunc, 0)
// 全局 panic 捕获
globalMiddlewareList = append(globalMiddlewareList, middleware.CustomRecover())
if nil != option.initContextData {
globalMiddlewareList = append(globalMiddlewareList, option.initContextData) // 初始化一些全局的变量
}