opt: parameter verification of optimized handler methods (#2224)

This commit is contained in:
ivothgle
2022-10-20 19:36:01 +08:00
committed by GitHub
parent ee6103418b
commit 33fdde6afd
2 changed files with 4 additions and 4 deletions

View File

@ -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"`,

View File

@ -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"`,