完善 RequestHandler 逻辑

This commit is contained in:
2025-02-07 16:10:33 +08:00
parent 196c437cc5
commit 77ea723e86
4 changed files with 99 additions and 15 deletions

View File

@ -94,6 +94,7 @@ func (c controller) methodConfig(methodType reflect.Type) (cfg UriConfig, needRe
needRegister = false
return
}
// 解析第一个返回值, 要求必须是结构体或者是map
if methodType.Out(0).Kind() != reflect.Struct && methodType.Out(0).Kind() != reflect.Map {
needRegister = false
@ -121,5 +122,29 @@ func (c controller) methodConfig(methodType reflect.Type) (cfg UriConfig, needRe
cfg.Method = metaField.Tag.Get(TagNameMethod)
cfg.Desc = metaField.Tag.Get(TagNameDesc)
cfg.TagList = strings.Split(metaField.Tag.Get(TagNameUriTag), ",")
// 解析参数配置
cfg.ParamList = c.parseParamConfig(formType)
return
}
// parseParamConfig 解析参数配置
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 14:35 2025/2/7
func (c controller) parseParamConfig(formDataType reflect.Type) []UriParam {
res := make([]UriParam, 0)
for i := 0; i < formDataType.NumField(); i++ {
structField := formDataType.Field(i)
if structField.Name == FieldNameMeta {
// Meta 字段, 忽略
continue
}
jsonTag := structField.Tag.Get("json")
if jsonTag == "" {
jsonTag = structField.Name
}
}
return res
}