upgrade: 支持初始化上下文数据中间件 + 支持自动启用请求初始化中间件
This commit is contained in:
@ -9,10 +9,11 @@ package router
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"git.zhangdeman.cn/zhangdeman/graceful"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"git.zhangdeman.cn/zhangdeman/graceful"
|
||||
|
||||
"git.zhangdeman.cn/zhangdeman/gin/define"
|
||||
|
||||
apiDoc "git.zhangdeman.cn/gateway/api-doc"
|
||||
@ -74,6 +75,12 @@ func NewServer(port int, optionList ...SetServerOptionFunc) *server {
|
||||
}
|
||||
option := newServerOption(port, optionList...)
|
||||
globalMiddlewareList := make([]gin.HandlerFunc, 0)
|
||||
if nil != option.initContextData {
|
||||
globalMiddlewareList = append(globalMiddlewareList, option.initContextData) // 初始化一些全局的变量
|
||||
}
|
||||
if !option.disableInitRequest { // 启用了初始化请求
|
||||
globalMiddlewareList = append(globalMiddlewareList, middleware.InitRequest()) // 初始化请求
|
||||
}
|
||||
// CustomContext 必须在第一个, 并且进行初始化
|
||||
globalMiddlewareList = append(
|
||||
globalMiddlewareList,
|
||||
|
Reference in New Issue
Block a user