反射支持 controller 指针与普通实例; 函数调用支持指针参数与非指针参数
This commit is contained in:
@ -37,21 +37,9 @@ func (c controller) Parse(inputController any) map[string]UriConfig {
|
||||
return parseRes
|
||||
}
|
||||
controllerType := reflect.TypeOf(inputController)
|
||||
inputController = reflect.New(controllerType).Interface()
|
||||
controllerType = reflect.TypeOf(inputController)
|
||||
controllerValue := reflect.ValueOf(inputController)
|
||||
/*if controllerType.Kind() == reflect.Func {
|
||||
// 直接函数注册
|
||||
cfg, isNeedRegister := c.methodConfig(controllerType)
|
||||
if isNeedRegister {
|
||||
parseRes[cfg.Path] = cfg
|
||||
}
|
||||
return parseRes
|
||||
}*/
|
||||
if controllerType.Kind() == reflect.Ptr {
|
||||
controllerValue = controllerValue.Elem()
|
||||
}
|
||||
/*if controllerValue.IsNil() {
|
||||
return parseRes
|
||||
}*/
|
||||
for methodIdx := 0; methodIdx < controllerType.NumMethod(); methodIdx++ {
|
||||
uriCfg, needRegister := c.methodConfig(controllerType.Method(methodIdx))
|
||||
if !needRegister {
|
||||
@ -88,10 +76,10 @@ func (c controller) methodConfig(reflectMethod reflect.Method) (cfg UriConfig, n
|
||||
}
|
||||
// 解析第二个参数是组合Meta的form表单
|
||||
formType := methodType.In(2)
|
||||
cfg.FormDataType = formType
|
||||
if formType.Kind() == reflect.Ptr {
|
||||
formType = methodType.In(2).Elem()
|
||||
}
|
||||
cfg.FormDataType = formType
|
||||
metaField, metaFieldExist := formType.FieldByName(FieldNameMeta)
|
||||
if !metaFieldExist {
|
||||
needRegister = false
|
||||
|
Reference in New Issue
Block a user