mirror of
https://gitee.com/johng/gf
synced 2026-06-06 02:25:47 +08:00
opt: parameter verification of optimized handler methods (#2224)
This commit is contained in:
@ -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"`,
|
||||
|
||||
@ -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"`,
|
||||
|
||||
Reference in New Issue
Block a user