修复URL注册BUG
This commit is contained in:
@ -9,6 +9,7 @@ package router
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// controller 解析controller有哪些方法要注册为接口
|
||||
@ -91,7 +92,7 @@ func (c controller) methodConfig(reflectMethod reflect.Method) (cfg UriConfig, n
|
||||
formType = methodType.In(2).Elem()
|
||||
}
|
||||
cfg.FormDataType = formType
|
||||
_, metaFieldExist := formType.FieldByName(FieldNameMeta)
|
||||
metaField, metaFieldExist := formType.FieldByName(FieldNameMeta)
|
||||
if !metaFieldExist {
|
||||
needRegister = false
|
||||
return
|
||||
@ -116,6 +117,23 @@ func (c controller) methodConfig(reflectMethod reflect.Method) (cfg UriConfig, n
|
||||
return
|
||||
}
|
||||
}
|
||||
// 解析meta信息
|
||||
cfg.Path = metaField.Tag.Get(TagNamePath)
|
||||
cfg.RequestMethod = metaField.Tag.Get(TagNameMethod)
|
||||
cfg.Desc = metaField.Tag.Get(TagNameDesc)
|
||||
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.ApiLogicFunc = reflectMethod
|
||||
needRegister = true
|
||||
return
|
||||
|
Reference in New Issue
Block a user