Documentation
¶
Overview ¶
Package router ...
Description : router ...
Author : go_developer@163.com<白茶清欢>
Date : 2025-02-07 17:41
Package router ...
Description : router ...
Author : go_developer@163.com<白茶清欢>
Date : 2025-01-27 15:29
Package router ...
Description : router ...
Author : go_developer@163.com<白茶清欢>
Date : 2024-07-20 22:57
Package router ...
Description : router ...
Author : go_developer@163.com<白茶清欢>
Date : 2025-02-14 21:48
Package router ...
Description : router ...
Author : go_developer@163.com<白茶清欢>
Date : 2025-01-27 19:42
Package router ...
Description : router ...
Author : go_developer@163.com<白茶清欢>
Date : 2024-07-20 21:40
Package router ...
Description : router ...
Author : go_developer@163.com<白茶清欢>
Date : 2025-02-18 17:26
Package router ...
Description : router ...
Author : go_developer@163.com<白茶清欢>
Date : 2024-07-20 21:39
Package router ...
Description : router ...
Author : go_developer@163.com<白茶清欢>
Date : 2025-02-07 18:19
Package router ...
Description : router ...
Author : go_developer@163.com<白茶清欢>
Date : 2025-02-07 17:36
Index ¶
- Constants
- Variables
- func GetValidateErr(obj any, rawErr error) error
- func NewServer(port int, optionList ...SetServerOptionFunc) *server
- func Register(port int, controllerList ...any) error
- func RequestHandler(uriCfg UriConfig) gin.HandlerFunc
- func SetValidateErrTag(tagName string)
- type Doc
- type Meta
- type SetServerOptionFunc
- func WithDisableSwaggerDoc() SetServerOptionFunc
- func WithEnableCors() SetServerOptionFunc
- func WithEnableRequestInit() SetServerOptionFunc
- func WithGlobalMiddlewareList(middlewareList ...gin.HandlerFunc) SetServerOptionFunc
- func WithLoggerCfg(loggerCfg *middleware.AccessConfig) SetServerOptionFunc
- func WithPprofEnable() SetServerOptionFunc
- func WithServerInfo(serverInfo *apiDocDefine.Info) SetServerOptionFunc
- func WithServerList(serverList []*apiDocDefine.ServerItem) SetServerOptionFunc
- func WithSwaggerBaseUri(baseUri string) SetServerOptionFunc
- func WithSwaggerUITheme(uiTheme string) SetServerOptionFunc
- type UriConfig
- type UriParam
Constants ¶
const ( PrefixFuncName = "RouterPrefix" // 路由前缀函数名称 MiddlewareFuncName = "RouterMiddleware" // 路由中间件函数名称 GinContextType = "*gin.Context" // gin context 类型名称 ErrorType = "error" // error类型 ErrorInterfaceFuncName = "Error" // error接口需要实现的方法名称 )
const ( TagNamePath = "path" // 接口的请求路径 TagNameMethod = "method" // 接口的请求方法 TagNameUriTag = "tag" // 接口的tag TagNameDesc = "desc" // 接口的描述 TagNameOutputStrict = "output_strict" // 接口数据是否为严格模式 : 严格模式, 响应数据必须是结构体/map,非严格模式返回任意值 TagNameBinding = "binding" // gin 内置的验证规则tag TagNameValidate = "validate" // validator v10 默认的验证规则tag TagNameErrMsg = "err" // 验证失败错误信息tag )
const (
FieldNameMeta = "Meta" // 元信息字段
)
Variables ¶
var (
Debug = false // 是否开启DEBUG
)
Functions ¶
func GetValidateErr ¶
GetValidateErr 格式化错误信息
Author : go_developer@163.com<白茶清欢>
Date : 22:19 2025/1/15
func NewServer ¶
func NewServer(port int, optionList ...SetServerOptionFunc) *server
NewServer server实例
Author : go_developer@163.com<白茶清欢>
Date : 18:20 2025/2/7
func RequestHandler ¶
func RequestHandler(uriCfg UriConfig) gin.HandlerFunc
RequestHandler 获取请求处理方法
Author : go_developer@163.com<白茶清欢>
Date : 19:44 2025/1/27
func SetValidateErrTag ¶
func SetValidateErrTag(tagName string)
SetValidateErrTag 设置验证失败时, 获取错误信息的tag字段
Author : go_developer@163.com<白茶清欢>
Date : 17:42 2025/2/7
Types ¶
type Doc ¶
type Doc struct {
// contains filtered or unexported fields
}
func (*Doc) Data ¶
func (d *Doc) Data() *define.OpenapiDoc
Data 文档数据
Author : go_developer@163.com<白茶清欢>
Date : 21:59 2025/2/14
type Meta ¶
type Meta struct{}
Meta 接口的元信息, 主要包含如下信息:
uri: 接口路由(不包含group前缀)
method: 请求方法: get/post 等
Author : go_developer@163.com<白茶清欢>
Date : 21:40 2024/7/20
type SetServerOptionFunc ¶
type SetServerOptionFunc func(so *serverOption)
func WithDisableSwaggerDoc ¶
func WithDisableSwaggerDoc() SetServerOptionFunc
WithDisableSwaggerDoc 禁用swagger文档
Author : go_developer@163.com<白茶清欢>
Date : 17:35 2025/2/18
func WithEnableCors ¶
func WithEnableCors() SetServerOptionFunc
WithEnableCors 启用全局跨域
Author : go_developer@163.com<白茶清欢>
Date : 14:56 2025/2/22
func WithEnableRequestInit ¶
func WithEnableRequestInit() SetServerOptionFunc
WithEnableRequestInit 全局配置初始化
Author : go_developer@163.com<白茶清欢>
Date : 14:56 2025/2/22
func WithGlobalMiddlewareList ¶
func WithGlobalMiddlewareList(middlewareList ...gin.HandlerFunc) SetServerOptionFunc
WithGlobalMiddlewareList 设置全局中间件
Author : go_developer@163.com<白茶清欢>
Date : 17:33 2025/2/18
func WithLoggerCfg ¶
func WithLoggerCfg(loggerCfg *middleware.AccessConfig) SetServerOptionFunc
WithLoggerCfg ...
Author : go_developer@163.com<白茶清欢>
Date : 15:25 2025/2/22
func WithPprofEnable ¶
func WithPprofEnable() SetServerOptionFunc
WithPprofEnable 启用pprof
Author : go_developer@163.com<白茶清欢>
Date : 15:10 2025/2/21
func WithServerInfo ¶
func WithServerInfo(serverInfo *apiDocDefine.Info) SetServerOptionFunc
WithServerInfo 设置serverInfo
Author : go_developer@163.com<白茶清欢>
Date : 17:51 2025/2/18
func WithServerList ¶
func WithServerList(serverList []*apiDocDefine.ServerItem) SetServerOptionFunc
WithServerList 设置服务器列表
Author : go_developer@163.com<白茶清欢>
Date : 17:52 2025/2/18
func WithSwaggerBaseUri ¶
func WithSwaggerBaseUri(baseUri string) SetServerOptionFunc
WithSwaggerBaseUri ...
Author : go_developer@163.com<白茶清欢>
Date : 18:05 2025/2/18
func WithSwaggerUITheme ¶
func WithSwaggerUITheme(uiTheme string) SetServerOptionFunc
WithSwaggerUITheme 设置swaggerUI主题
Author : go_developer@163.com<白茶清欢>
Date : 17:29 2025/2/18
type UriConfig ¶
type UriConfig struct { Path string `json:"path"` // 接口路由, 必须配置 RequestMethod string `json:"request_method"` // 接口请求方法, 必须配置 TagList []string `json:"tag_list"` // 接口分组 Desc string `json:"desc"` // 接口描述 OutputStrict bool `json:"output_strict"` // 接口是否为严格模式 : 不配置,可返回任意类型, 配置, 必须返回结构体或者map FormDataType reflect.Type `json:"-"` // 表单数据类型 ResultDataType reflect.Type `json:"-"` // 返回值数据类型 ApiStructValue reflect.Value `json:"-"` // 逻辑函数所属结构体取值 ApiLogicFunc reflect.Method `json:"-"` // 自定义的接口逻辑 }
UriConfig 接口配置
Author : go_developer@163.com<白茶清欢>
Date : 15:41 2024/7/21
type UriParam ¶
type UriParam struct { Field string `json:"field"` // 结构体字段 Name string `json:"name"` // 参数名称 Type string `json:"type"` // 参数类型 Validate string `json:"validate"` // 验证规则: validator/v10 库 ErrorMsg string `json:"error_msg"` // 验证失败的错误信息 DisableAutoType bool `json:"disable_auto_type"` // 禁用自动类型转换 Sort string `json:"sort"` // 参数读取顺序: 默认 POST : body > query > path GET : query > path > body }
UriParam 接口参数配置
Author : go_developer@163.com<白茶清欢>
Date : 15:40 2025/1/27