From 4077b6fdf05624819c4f727064f45b0cf310a3aa Mon Sep 17 00:00:00 2001 From: Jason li Date: Sat, 23 Jan 2021 18:30:41 +0800 Subject: [PATCH] fix pointer receiver method expiression --- server/web/router.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/server/web/router.go b/server/web/router.go index d7fd3047..fba35aaf 100644 --- a/server/web/router.go +++ b/server/web/router.go @@ -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 }