feat: 增加接口流量配置中间件
This commit is contained in:
@@ -7,10 +7,6 @@
|
||||
// Date : 2024-07-20 22:57
|
||||
package router
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
)
|
||||
|
||||
const (
|
||||
PrefixFuncName = "RouterPrefix" // 路由前缀函数名称
|
||||
MiddlewareFuncName = "RouterMiddleware" // 路由中间件函数名称
|
||||
@@ -30,30 +26,12 @@ const (
|
||||
TagNameHookSync = "hook-sync" // hook 同步执行
|
||||
TagNameNoLogin = "no-login" // 接口是否需要登录(无需登录, 则有token就验证, 无token不验证)
|
||||
TagNameMaxExecTime = "max-exec-time" // 接口最大执行时间, 单位: s, 配置为0则不验证
|
||||
TagNameRateLimit = "rate-limit" // 接口限流
|
||||
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 int64 `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"` // 结构体字段
|
||||
|
||||
Reference in New Issue
Block a user