feat: 接入新版本openapi文档, 页面渲染兼容性待调试
This commit is contained in:
@@ -8,9 +8,6 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
apiDocDefine "git.zhangdeman.cn/zhangdeman/api-doc/define"
|
||||
"git.zhangdeman.cn/zhangdeman/gin/middleware"
|
||||
"git.zhangdeman.cn/zhangdeman/rate_limit/abstract"
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -20,18 +17,14 @@ type SetServerOptionFunc func(so *serverOption)
|
||||
|
||||
// serverOption 获取server实例的选项
|
||||
type serverOption struct {
|
||||
swaggerUiTheme string // swagger 主题
|
||||
swaggerBaseUri string // swagger 基础path
|
||||
globalMiddlewareList []gin.HandlerFunc // 全局中间件列表
|
||||
disableSwaggerDoc bool // 禁用swagger文档, 特定环境不想展示文档, 可通过次方式禁用
|
||||
serverInfo *apiDocDefine.Info // 服务器信息
|
||||
serverList []*apiDocDefine.ServerItem // 服务器环境列表
|
||||
enablePprof bool // 启用 pprof
|
||||
enableCors bool // 启动跨域支持
|
||||
disableInitRequest bool // 禁用初始化请求
|
||||
loggerCfg *middleware.AccessConfig // 日志配置
|
||||
initContextData gin.HandlerFunc // 初始化一些请求数据
|
||||
rateLimitInstance abstract.IRateLimit // 服务流控实例
|
||||
docConfig DocConfig // 文档配置
|
||||
globalMiddlewareList []gin.HandlerFunc // 全局中间件列表
|
||||
enablePprof bool // 启用 pprof
|
||||
enableCors bool // 启动跨域支持
|
||||
disableInitRequest bool // 禁用初始化请求
|
||||
loggerCfg *middleware.AccessConfig // 日志配置
|
||||
initContextData gin.HandlerFunc // 初始化一些请求数据
|
||||
rateLimitInstance abstract.IRateLimit // 服务流控实例
|
||||
}
|
||||
|
||||
// WithRateLimitInstance 设置流控实例, 配置为 nil, 代表禁用
|
||||
@@ -59,14 +52,13 @@ func WithInitContextData(formatFunc func(ctx *gin.Context)) SetServerOptionFunc
|
||||
}
|
||||
}
|
||||
|
||||
// WithSwaggerUITheme 设置swaggerUI主题
|
||||
func WithSwaggerUITheme(uiTheme string) SetServerOptionFunc {
|
||||
// WithDocConfig 设置文档配置
|
||||
func WithDocConfig(docConfig *DocConfig) SetServerOptionFunc {
|
||||
return func(so *serverOption) {
|
||||
uiTheme = strings.TrimSpace(uiTheme)
|
||||
if len(uiTheme) == 0 {
|
||||
if nil == docConfig {
|
||||
return
|
||||
}
|
||||
so.swaggerUiTheme = uiTheme
|
||||
so.docConfig = *docConfig
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,45 +69,6 @@ func WithGlobalMiddlewareList(middlewareList ...gin.HandlerFunc) SetServerOption
|
||||
}
|
||||
}
|
||||
|
||||
// WithSwaggerBaseUri ...
|
||||
func WithSwaggerBaseUri(baseUri string) SetServerOptionFunc {
|
||||
return func(so *serverOption) {
|
||||
baseUri = strings.TrimSpace(baseUri)
|
||||
if len(baseUri) == 0 {
|
||||
return
|
||||
}
|
||||
baseUri = "/" + strings.TrimLeft(baseUri, "/")
|
||||
so.swaggerBaseUri = baseUri
|
||||
}
|
||||
}
|
||||
|
||||
// WithDisableSwaggerDoc 禁用swagger文档
|
||||
func WithDisableSwaggerDoc() SetServerOptionFunc {
|
||||
return func(so *serverOption) {
|
||||
so.disableSwaggerDoc = true
|
||||
}
|
||||
}
|
||||
|
||||
// WithServerInfo 设置serverInfo
|
||||
func WithServerInfo(serverInfo *apiDocDefine.Info) SetServerOptionFunc {
|
||||
return func(so *serverOption) {
|
||||
if nil == serverInfo {
|
||||
return
|
||||
}
|
||||
so.serverInfo = serverInfo
|
||||
}
|
||||
}
|
||||
|
||||
// WithServerList 设置服务器列表
|
||||
func WithServerList(serverList []*apiDocDefine.ServerItem) SetServerOptionFunc {
|
||||
return func(so *serverOption) {
|
||||
if len(serverList) == 0 {
|
||||
return
|
||||
}
|
||||
so.serverList = serverList
|
||||
}
|
||||
}
|
||||
|
||||
// WithPprofEnable 启用pprof
|
||||
func WithPprofEnable() SetServerOptionFunc {
|
||||
return func(so *serverOption) {
|
||||
|
||||
Reference in New Issue
Block a user