From 33fdde6afdbca55478f3c0e6984be8052134450b Mon Sep 17 00:00:00 2001 From: ivothgle Date: Thu, 20 Oct 2022 19:36:01 +0800 Subject: [PATCH] opt: parameter verification of optimized handler methods (#2224) --- net/ghttp/ghttp_server_service_handler.go | 4 ++-- os/gcmd/gcmd_command_object.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/net/ghttp/ghttp_server_service_handler.go b/net/ghttp/ghttp_server_service_handler.go index 25b4208f9..9e17523c8 100644 --- a/net/ghttp/ghttp_server_service_handler.go +++ b/net/ghttp/ghttp_server_service_handler.go @@ -164,7 +164,7 @@ func (s *Server) checkAndCreateFuncInfo(f interface{}, pkgPath, structName, meth return } - if reflectType.In(0).String() != "context.Context" { + if !reflectType.In(0).Implements(reflect.TypeOf((*context.Context)(nil)).Elem()) { err = gerror.NewCodef( gcode.CodeInvalidParameter, `invalid handler: defined as "%s", but the first input parameter should be type of "context.Context"`, @@ -173,7 +173,7 @@ func (s *Server) checkAndCreateFuncInfo(f interface{}, pkgPath, structName, meth return } - if reflectType.Out(1).String() != "error" { + if !reflectType.Out(1).Implements(reflect.TypeOf((*error)(nil)).Elem()) { err = gerror.NewCodef( gcode.CodeInvalidParameter, `invalid handler: defined as "%s", but the last output parameter should be type of "error"`, diff --git a/os/gcmd/gcmd_command_object.go b/os/gcmd/gcmd_command_object.go index c1f6b29ab..07c11ed5b 100644 --- a/os/gcmd/gcmd_command_object.go +++ b/os/gcmd/gcmd_command_object.go @@ -187,7 +187,7 @@ func newCommandFromMethod( } return } - if methodType.In(0).String() != "context.Context" { + if !methodType.In(0).Implements(reflect.TypeOf((*context.Context)(nil)).Elem()) { err = gerror.NewCodef( gcode.CodeInvalidParameter, `invalid command: defined as "%s", but the first input parameter should be type of "context.Context"`, @@ -195,7 +195,7 @@ func newCommandFromMethod( ) return } - if methodType.Out(1).String() != "error" { + if !methodType.Out(1).Implements(reflect.TypeOf((*error)(nil)).Elem()) { err = gerror.NewCodef( gcode.CodeInvalidParameter, `invalid command: defined as "%s", but the last output parameter should be type of "error"`,