feat: 支持设置demo检查中间件
This commit is contained in:
@@ -25,6 +25,17 @@ type serverOption struct {
|
|||||||
loggerCfg *middleware.AccessConfig // 日志配置
|
loggerCfg *middleware.AccessConfig // 日志配置
|
||||||
initContextData gin.HandlerFunc // 初始化一些请求数据
|
initContextData gin.HandlerFunc // 初始化一些请求数据
|
||||||
rateLimitInstance abstract.IRateLimit // 服务流控实例
|
rateLimitInstance abstract.IRateLimit // 服务流控实例
|
||||||
|
demoCheck gin.HandlerFunc // demo检查
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithDemoCheck 设置demo检查
|
||||||
|
func WithDemoCheck(f gin.HandlerFunc) SetServerOptionFunc {
|
||||||
|
return func(so *serverOption) {
|
||||||
|
if nil == f {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
so.demoCheck = f
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithRateLimitInstance 设置流控实例, 配置为 nil, 代表禁用
|
// WithRateLimitInstance 设置流控实例, 配置为 nil, 代表禁用
|
||||||
|
|||||||
@@ -143,6 +143,10 @@ func (s *Server) getGlobalMiddlewareList(option *serverOption) {
|
|||||||
AllowFiles: true,
|
AllowFiles: true,
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
// demo 检查
|
||||||
|
if nil != option.demoCheck {
|
||||||
|
s.globalMiddlewareList = append(s.globalMiddlewareList, option.demoCheck)
|
||||||
|
}
|
||||||
if len(option.globalMiddlewareList) > 0 {
|
if len(option.globalMiddlewareList) > 0 {
|
||||||
// 自定义全局中间件追加
|
// 自定义全局中间件追加
|
||||||
s.globalMiddlewareList = append(s.globalMiddlewareList, option.globalMiddlewareList...)
|
s.globalMiddlewareList = append(s.globalMiddlewareList, option.globalMiddlewareList...)
|
||||||
|
|||||||
Reference in New Issue
Block a user