接口逻辑函数返回值严格校验时, 校验不通过, 由忽略接口注册修改为panic
This commit is contained in:
parent
1b1964881f
commit
cb4718a269
@ -98,18 +98,6 @@ func (c controller) methodConfig(reflectMethod reflect.Method) (cfg UriConfig, n
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 解析第一个返回值, 要求必须是结构体或者是map
|
|
||||||
outputStrictModel := metaField.Tag.Get(TagNameOutputStrict)
|
|
||||||
// 输出是否严格模式
|
|
||||||
cfg.OutputStrict = outputStrictModel == "1" || outputStrictModel == "true"
|
|
||||||
if cfg.OutputStrict {
|
|
||||||
// 开启输出严格模式校验
|
|
||||||
if methodType.Out(0).Kind() != reflect.Struct && methodType.Out(0).Kind() != reflect.Map {
|
|
||||||
needRegister = false
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if methodType.Out(1).Kind().String() != ErrorType {
|
if methodType.Out(1).Kind().String() != ErrorType {
|
||||||
// 判断是否是实现 error接口的方法
|
// 判断是否是实现 error接口的方法
|
||||||
outputErrParse := false
|
outputErrParse := false
|
||||||
@ -132,6 +120,16 @@ func (c controller) methodConfig(reflectMethod reflect.Method) (cfg UriConfig, n
|
|||||||
cfg.RequestMethod = metaField.Tag.Get(TagNameMethod)
|
cfg.RequestMethod = metaField.Tag.Get(TagNameMethod)
|
||||||
cfg.Desc = metaField.Tag.Get(TagNameDesc)
|
cfg.Desc = metaField.Tag.Get(TagNameDesc)
|
||||||
cfg.TagList = strings.Split(metaField.Tag.Get(TagNameUriTag), ",")
|
cfg.TagList = strings.Split(metaField.Tag.Get(TagNameUriTag), ",")
|
||||||
|
// 解析第一个返回值, 要求必须是结构体或者是map
|
||||||
|
outputStrictModel := metaField.Tag.Get(TagNameOutputStrict)
|
||||||
|
cfg.OutputStrict = outputStrictModel == "1" || outputStrictModel == "true"
|
||||||
|
if cfg.OutputStrict {
|
||||||
|
// 开启输出严格模式校验
|
||||||
|
if methodType.Out(0).Kind() != reflect.Struct && methodType.Out(0).Kind() != reflect.Map {
|
||||||
|
panic(cfg.Path + " : 接口配置输出严格校验, 输出数据类型必须为 struct 或 *struct 或 map, 实际返回数据类型 : " + methodType.Out(0).Kind().String())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
// 解析参数配置
|
// 解析参数配置
|
||||||
cfg.ParamList = c.parseParamConfig(formType)
|
cfg.ParamList = c.parseParamConfig(formType)
|
||||||
cfg.ApiLogicFunc = reflectMethod
|
cfg.ApiLogicFunc = reflectMethod
|
||||||
|
@ -20,7 +20,7 @@ func (t TestController) Logic(ctx *gin.Context, formData *TestForm) (any, error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
type TestForm struct {
|
type TestForm struct {
|
||||||
Meta `tag:"测试表单" path:"/a/b/c/d" desc:"测试接口" method:"get" strict:"true"`
|
Meta `tag:"测试表单" path:"/a/b/c/d" desc:"测试接口" method:"get"`
|
||||||
Age int `json:"age" form:"age" binding:"min=20"`
|
Age int `json:"age" form:"age" binding:"min=20"`
|
||||||
Name string `json:"name" form:"name"`
|
Name string `json:"name" form:"name"`
|
||||||
Test *Test `json:"test" form:"test"`
|
Test *Test `json:"test" form:"test"`
|
||||||
|
Loading…
x
Reference in New Issue
Block a user