fix pointer receiver method expiression

This commit is contained in:
Jason li 2021-01-23 18:30:41 +08:00
parent 422498af8d
commit 4077b6fdf0

View File

@ -584,12 +584,7 @@ func getReflectTypeAndMethod(f interface{}) (controllerType reflect.Type, method
panic("invalid number of param in")
}
// check the receiver implement ControllerInterface
controllerType = funcType.In(0)
_, ok := reflect.New(controllerType).Interface().(ControllerInterface)
if !ok {
panic(controllerType.String() + " is not implemented ControllerInterface")
}
// check controller has the method
_, exists := controllerType.MethodByName(method)
@ -597,6 +592,16 @@ func getReflectTypeAndMethod(f interface{}) (controllerType reflect.Type, method
panic(controllerType.String() + " has no method " + method)
}
// check the receiver implement ControllerInterface
if controllerType.Kind() == reflect.Ptr {
controllerType = controllerType.Elem()
}
controller := reflect.New(controllerType)
_, ok := controller.Interface().(ControllerInterface)
if !ok {
panic(controllerType.String() + " is not implemented ControllerInterface")
}
return
}