增加CustomContext
This commit is contained in:
@ -9,13 +9,14 @@ package router
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
apiDoc "git.zhangdeman.cn/gateway/api-doc"
|
||||
"git.zhangdeman.cn/zhangdeman/consts"
|
||||
"git.zhangdeman.cn/zhangdeman/gin/middleware"
|
||||
"git.zhangdeman.cn/zhangdeman/gin/middleware/request_cors"
|
||||
"github.com/gin-contrib/pprof"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
apiDocDefine "git.zhangdeman.cn/gateway/api-doc/define"
|
||||
"github.com/gin-gonic/gin"
|
||||
@ -70,10 +71,14 @@ func NewServer(port int, optionList ...SetServerOptionFunc) *server {
|
||||
}
|
||||
option := newServerOption(port, optionList...)
|
||||
globalMiddlewareList := make([]gin.HandlerFunc, 0)
|
||||
if option.enableRequestInit {
|
||||
// 初始化请求中间件
|
||||
globalMiddlewareList = append(globalMiddlewareList, middleware.InitRequest())
|
||||
}
|
||||
// CustomContext 必须在第一个, 并且进行初始化
|
||||
globalMiddlewareList = append(
|
||||
globalMiddlewareList,
|
||||
func(ctx *gin.Context) {
|
||||
// 初始化上下文以及基础信息
|
||||
_ = NewContext(ctx)
|
||||
},
|
||||
)
|
||||
if nil != option.loggerCfg {
|
||||
// 请求日志记录中间件
|
||||
globalMiddlewareList = append(globalMiddlewareList, middleware.LogRequest(option.loggerCfg))
|
||||
|
Reference in New Issue
Block a user