引入文档解析
This commit is contained in:
@ -9,7 +9,6 @@ package router
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// controller 解析controller有哪些方法要注册为接口
|
||||
@ -92,12 +91,14 @@ func (c controller) methodConfig(reflectMethod reflect.Method) (cfg UriConfig, n
|
||||
formType = methodType.In(2).Elem()
|
||||
}
|
||||
cfg.FormDataType = formType
|
||||
metaField, metaFieldExist := formType.FieldByName(FieldNameMeta)
|
||||
_, metaFieldExist := formType.FieldByName(FieldNameMeta)
|
||||
if !metaFieldExist {
|
||||
needRegister = false
|
||||
return
|
||||
}
|
||||
|
||||
cfg.ResultDataType = methodType.Out(0)
|
||||
if cfg.ResultDataType == nil {
|
||||
}
|
||||
if methodType.Out(1).Kind().String() != ErrorType {
|
||||
// 判断是否是实现 error接口的方法
|
||||
outputErrParse := false
|
||||
@ -115,23 +116,6 @@ 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