优化升级gin框架的二次包装 #19

Merged
zhangdeman merged 12 commits from feature/upgrade_gin into master 2025-12-29 10:40:06 +08:00
2 changed files with 5 additions and 45 deletions
Showing only changes of commit 25cc9564a2 - Show all commits

View File

@@ -18,10 +18,6 @@ import (
type SetServerOptionFunc func(so *serverOption) type SetServerOptionFunc func(so *serverOption)
// serverOption 获取server实例的选项 // serverOption 获取server实例的选项
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 17:28 2025/2/18
type serverOption struct { type serverOption struct {
swaggerUiTheme string // swagger 主题 swaggerUiTheme string // swagger 主题
swaggerBaseUri string // swagger基础path swaggerBaseUri string // swagger基础path
@@ -60,10 +56,6 @@ func WithInitContextData(formatFunc func(ctx *gin.Context) map[string]any) SetSe
} }
// WithSwaggerUITheme 设置swaggerUI主题 // WithSwaggerUITheme 设置swaggerUI主题
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 17:29 2025/2/18
func WithSwaggerUITheme(uiTheme string) SetServerOptionFunc { func WithSwaggerUITheme(uiTheme string) SetServerOptionFunc {
return func(so *serverOption) { return func(so *serverOption) {
uiTheme = strings.TrimSpace(uiTheme) uiTheme = strings.TrimSpace(uiTheme)
@@ -75,10 +67,6 @@ func WithSwaggerUITheme(uiTheme string) SetServerOptionFunc {
} }
// WithGlobalMiddlewareList 设置全局中间件 // WithGlobalMiddlewareList 设置全局中间件
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 17:33 2025/2/18
func WithGlobalMiddlewareList(middlewareList ...gin.HandlerFunc) SetServerOptionFunc { func WithGlobalMiddlewareList(middlewareList ...gin.HandlerFunc) SetServerOptionFunc {
return func(so *serverOption) { return func(so *serverOption) {
so.globalMiddlewareList = middlewareList so.globalMiddlewareList = middlewareList
@@ -86,10 +74,6 @@ func WithGlobalMiddlewareList(middlewareList ...gin.HandlerFunc) SetServerOption
} }
// WithSwaggerBaseUri ... // WithSwaggerBaseUri ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 18:05 2025/2/18
func WithSwaggerBaseUri(baseUri string) SetServerOptionFunc { func WithSwaggerBaseUri(baseUri string) SetServerOptionFunc {
return func(so *serverOption) { return func(so *serverOption) {
baseUri = strings.TrimSpace(baseUri) baseUri = strings.TrimSpace(baseUri)
@@ -102,10 +86,6 @@ func WithSwaggerBaseUri(baseUri string) SetServerOptionFunc {
} }
// WithDisableSwaggerDoc 禁用swagger文档 // WithDisableSwaggerDoc 禁用swagger文档
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 17:35 2025/2/18
func WithDisableSwaggerDoc() SetServerOptionFunc { func WithDisableSwaggerDoc() SetServerOptionFunc {
return func(so *serverOption) { return func(so *serverOption) {
so.disableSwaggerDoc = true so.disableSwaggerDoc = true
@@ -113,10 +93,6 @@ func WithDisableSwaggerDoc() SetServerOptionFunc {
} }
// WithServerInfo 设置serverInfo // WithServerInfo 设置serverInfo
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 17:51 2025/2/18
func WithServerInfo(serverInfo *apiDocDefine.Info) SetServerOptionFunc { func WithServerInfo(serverInfo *apiDocDefine.Info) SetServerOptionFunc {
return func(so *serverOption) { return func(so *serverOption) {
if nil == serverInfo { if nil == serverInfo {
@@ -127,10 +103,6 @@ func WithServerInfo(serverInfo *apiDocDefine.Info) SetServerOptionFunc {
} }
// WithServerList 设置服务器列表 // WithServerList 设置服务器列表
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 17:52 2025/2/18
func WithServerList(serverList []*apiDocDefine.ServerItem) SetServerOptionFunc { func WithServerList(serverList []*apiDocDefine.ServerItem) SetServerOptionFunc {
return func(so *serverOption) { return func(so *serverOption) {
if len(serverList) == 0 { if len(serverList) == 0 {
@@ -141,10 +113,6 @@ func WithServerList(serverList []*apiDocDefine.ServerItem) SetServerOptionFunc {
} }
// WithPprofEnable 启用pprof // WithPprofEnable 启用pprof
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 15:10 2025/2/21
func WithPprofEnable() SetServerOptionFunc { func WithPprofEnable() SetServerOptionFunc {
return func(so *serverOption) { return func(so *serverOption) {
so.enablePprof = true so.enablePprof = true
@@ -152,10 +120,6 @@ func WithPprofEnable() SetServerOptionFunc {
} }
// WithEnableCors 启用全局跨域 // WithEnableCors 启用全局跨域
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 14:56 2025/2/22
func WithEnableCors() SetServerOptionFunc { func WithEnableCors() SetServerOptionFunc {
return func(so *serverOption) { return func(so *serverOption) {
so.enableCors = true so.enableCors = true
@@ -163,10 +127,6 @@ func WithEnableCors() SetServerOptionFunc {
} }
// WithLoggerCfg ... // WithLoggerCfg ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 15:25 2025/2/22
func WithLoggerCfg(loggerCfg *middleware.AccessConfig) SetServerOptionFunc { func WithLoggerCfg(loggerCfg *middleware.AccessConfig) SetServerOptionFunc {
return func(so *serverOption) { return func(so *serverOption) {
if nil != loggerCfg || nil != loggerCfg.Logger { if nil != loggerCfg || nil != loggerCfg.Logger {