Files
gin/router/define.go

71 lines
3.8 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Package router ...
//
// Description : router ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2024-07-20 22:57
package router
import (
"reflect"
)
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" // 接口的描述
TagNameIsSse = "is-sse" // 是否 SSE 连接
TagNameIsWebsocket = "is-ws" // 是否 websocket 连接
TagNameOutputStrict = "output_strict" // 接口数据是否为严格模式 : 严格模式, 响应数据必须是结构体/map非严格模式返回任意值
TagNameHookSync = "hook-sync" // hook 同步执行
TagNameNoLogin = "no-login" // 接口是否需要登录(无需登录, 则有token就验证, 无token不验证)
TagNameMaxExecTime = "max-exec-time" // 接口最大执行时间, 单位: s, 配置为0则不验证
TagNameBinding = "binding" // gin 内置的验证规则tag
TagNameValidate = "validate" // validator v10 默认的验证规则tag
TagNameErrMsg = "err" // 验证失败错误信息 tag
)
// UriConfig 接口配置
type UriConfig struct {
Path string `json:"path"` // 接口路由, 必须配置
RequestMethod []string `json:"request_method"` // 接口请求方法, 必须配置
TagList []string `json:"tag_list"` // 接口分组
Desc string `json:"desc"` // 接口描述
IsSse bool `json:"is_sse"` // 是否 SSE 连接
IsWebsocket bool `json:"is_ws"` // 是否 websocket 连接
OutputStrict bool `json:"output_strict"` // 接口是否为严格模式 : 不配置,可返回任意类型, 配置, 必须返回结构体或者map
MaxExecTime uint `json:"max_exec_time"` // 接口最大执行时间, 单位: ms, 配置为0则不验证, 注意, 超时后不会报错, 会打印一条warn日志, 如果配置了报警策略, 也会发送报警信息
HookSync bool `json:"hook_sync"` // 接口主逻辑执行完成之后hook是否同步执行, 默认异步执行
NoLogin bool `json:"no_login"` // 接口是否需要登录(无需登录, 则有token就验证, 无token不验证)
ParamIsPtr bool `json:"param_is_ptr"` // 参数是否指针类型
FormDataType reflect.Type `json:"-"` // 表单数据类型
ResultDataType reflect.Type `json:"-"` // 返回值数据类型
ApiStructValue reflect.Value `json:"-"` // 逻辑函数所属结构体取值
ApiLogicFunc reflect.Method `json:"-"` // 自定义的接口逻辑
}
// 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
}
const (
FieldNameMeta = "Meta" // 元信息字段
)