This commit is contained in:
John Guo
2023-10-11 21:33:51 +08:00
committed by GitHub
parent 10b67fc7b0
commit 7f1ce2aff3
2 changed files with 26 additions and 2 deletions

View File

@ -197,6 +197,30 @@ func (s *Server) checkAndCreateFuncInfo(
return
}
if reflectType.In(1).Kind() != reflect.Ptr ||
(reflectType.In(1).Kind() == reflect.Ptr && reflectType.In(1).Elem().Kind() != reflect.Struct) {
err = gerror.NewCodef(
gcode.CodeInvalidParameter,
`invalid handler: defined as "%s", but the second input parameter should be type of pointer to struct like "*BizReq"`,
reflectType.String(),
)
return
}
// Do not enable this logic, as many users are already using none struct pointer type
// as the first output parameter.
/*
if reflectType.Out(0).Kind() != reflect.Ptr ||
(reflectType.Out(0).Kind() == reflect.Ptr && reflectType.Out(0).Elem().Kind() != reflect.Struct) {
err = gerror.NewCodef(
gcode.CodeInvalidParameter,
`invalid handler: defined as "%s", but the first output parameter should be type of pointer to struct like "*BizRes"`,
reflectType.String(),
)
return
}
*/
// The request struct should be named as `xxxReq`.
reqStructName := trimGeneric(reflectType.In(1).String())
if !gstr.HasSuffix(reqStructName, `Req`) {

View File

@ -391,7 +391,6 @@ func (c *Issue2890Controller) Post(ctx context.Context, req *Issue2890Req) (res
// https://github.com/gogf/gf/issues/2890
func Test_Issue2890(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
oldEnumsJson, err := gtag.GetGlobalEnums()
t.AssertNil(err)
defer t.AssertNil(gtag.SetGlobalEnums(oldEnumsJson))
@ -417,6 +416,7 @@ func Test_Issue2890(t *testing.T) {
)
t.Assert(
c.PostContent(ctx, "/api/v2/issue2890", `{"Enums":"c"}`),
"{\"code\":51,\"message\":\"The Enums value `c` should be in enums of: [\\\"a\\\",\\\"b\\\"]\",\"data\":null}")
"{\"code\":51,\"message\":\"The Enums value `c` should be in enums of: [\\\"a\\\",\\\"b\\\"]\",\"data\":null}",
)
})
}