feat: remove custom context
This commit is contained in:
@ -12,10 +12,6 @@ import "strings"
|
||||
var defaultValidateErrTag = "err"
|
||||
|
||||
// SetValidateErrTag 设置验证失败时, 获取错误信息的tag字段
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 17:42 2025/2/7
|
||||
func SetValidateErrTag(tagName string) {
|
||||
tagName = strings.TrimSpace(tagName)
|
||||
if tagName == "" {
|
||||
|
||||
@ -13,10 +13,6 @@ import (
|
||||
)
|
||||
|
||||
// controller 解析controller有哪些方法要注册为接口
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 15:30 2025/1/27
|
||||
type controller struct {
|
||||
}
|
||||
|
||||
@ -71,7 +67,7 @@ func (c controller) methodConfig(reflectMethod reflect.Method) (cfg UriConfig, n
|
||||
}
|
||||
// 第一个参数必须是 *gin.Context 或者 *define.Context
|
||||
paramOne := methodType.In(1).String()
|
||||
if paramOne != GinContextType && paramOne != CustomContextType {
|
||||
if paramOne != GinContextType {
|
||||
needRegister = false
|
||||
return
|
||||
}
|
||||
@ -107,7 +103,6 @@ func (c controller) methodConfig(reflectMethod reflect.Method) (cfg UriConfig, n
|
||||
}
|
||||
}
|
||||
// 解析meta信息
|
||||
cfg.CtxType = paramOne
|
||||
cfg.Path = metaField.Tag.Get(TagNamePath)
|
||||
cfg.RequestMethod = metaField.Tag.Get(TagNameMethod)
|
||||
cfg.Desc = metaField.Tag.Get(TagNameDesc)
|
||||
|
||||
@ -15,7 +15,6 @@ const (
|
||||
PrefixFuncName = "RouterPrefix" // 路由前缀函数名称
|
||||
MiddlewareFuncName = "RouterMiddleware" // 路由中间件函数名称
|
||||
GinContextType = "*gin.Context" // gin context 类型名称
|
||||
CustomContextType = "*define.Context" // custom context 类型名称
|
||||
ErrorType = "error" // error类型
|
||||
ErrorInterfaceFuncName = "Error" // error接口需要实现的方法名称
|
||||
)
|
||||
@ -42,7 +41,6 @@ type UriConfig struct {
|
||||
TagList []string `json:"tag_list"` // 接口分组
|
||||
Desc string `json:"desc"` // 接口描述
|
||||
OutputStrict bool `json:"output_strict"` // 接口是否为严格模式 : 不配置,可返回任意类型, 配置, 必须返回结构体或者map
|
||||
CtxType string `json:"ctx_type"` // ctx参数类型
|
||||
FormDataType reflect.Type `json:"-"` // 表单数据类型
|
||||
ResultDataType reflect.Type `json:"-"` // 返回值数据类型
|
||||
ApiStructValue reflect.Value `json:"-"` // 逻辑函数所属结构体取值
|
||||
|
||||
@ -114,12 +114,8 @@ func (s *server) RequestHandler(uriCfg UriConfig) gin.HandlerFunc {
|
||||
if uriCfg.FormDataType.Kind() != reflect.Ptr {
|
||||
inputValue = inputValue.Elem()
|
||||
}
|
||||
if uriCfg.CtxType == CustomContextType {
|
||||
customCtx := ctx.MustGet(define.CustomContextKey)
|
||||
firstParam = reflect.ValueOf(customCtx)
|
||||
} else {
|
||||
firstParam = reflect.ValueOf(ctx)
|
||||
}
|
||||
|
||||
firstParam = reflect.ValueOf(ctx)
|
||||
resList := uriCfg.ApiLogicFunc.Func.Call([]reflect.Value{uriCfg.ApiStructValue, firstParam, inputValue})
|
||||
if resList[1].IsNil() {
|
||||
// 请求成功
|
||||
|
||||
@ -13,7 +13,8 @@ package router
|
||||
//
|
||||
// method: 请求方法: get/post 等
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 21:40 2024/7/20
|
||||
// 使用示例如下:
|
||||
// type RequestForm struct {
|
||||
// Meta `json:"-" path:"接口路由" method:"get,post" sse:"1" tag:"接口分组标签" summary:"接口描述"`
|
||||
// }
|
||||
type Meta struct{}
|
||||
|
||||
Reference in New Issue
Block a user