-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] Validation rules using enums are invalid #2890
Comments
@shuqingzai But I cannot reproduce this using latest package main
import (
"fmt"
"reflect"
"github.com/gogf/gf/v2/errors/gerror"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gctx"
"github.com/gogf/gf/v2/util/gtag"
"github.com/gogf/gf/v2/util/gvalid"
)
type IEnum int
const (
EnumUnknown IEnum = 0
EnumEmail IEnum = 1
EnumName IEnum = 2
)
type SEnums string
const (
EnumUnknownStr SEnums = "unknown"
EnumEmailStr SEnums = "email"
EnumNameStr SEnums = "name"
)
type VEnumParam struct {
IType IEnum `json:"iType" v:"required|enums#类型不能为空|非允许的枚举数值Int"`
SType SEnums `json:"sType" v:"required|enums#类型不能为空|非允许的枚举数值Str"`
}
func main() {
var (
err error
ctx = gctx.New()
check = &VEnumParam{
IType: EnumEmail,
SType: EnumEmailStr,
}
)
enumsContent := fmt.Sprintf(
`{"%s":[0,1,2], "%s":["unknown","email","name"]}`,
reflect.TypeOf(check.IType).String(), reflect.TypeOf(check.SType).String(),
)
err = gtag.SetGlobalEnums(enumsContent)
if err != nil {
panic(err)
}
if err = g.Validator().Data(check).Run(ctx); err != nil {
g.Dump(err.(gvalid.Error).Maps())
g.Dump(gerror.Current(err))
g.Log().Warning(ctx, "validator failed")
return
}
g.Log().Info(ctx, "validator success")
} |
@gqcn |
@gqcn 这与 gf/net/ghttp/ghttp_request_param.go Line 112 in 7d4c59a
data 是一个 map[string]any gf/net/ghttp/ghttp_request_param.go Line 93 in 141ca62
且被赋值到 gf/net/ghttp/ghttp_request_param.go Line 115 in 7d4c59a
@gqcn |
@gqcn This is related to gf/net/ghttp/ghttp_request_param.go Line 112 in 7d4c59a
data is a map[string]any assigned to v.assoc gf/net/ghttp/ghttp_request_param.go Line 115 in 7d4c59a
@gqcn |
please remove inactive label. |
@shuqingzai 好的,我来构造一个http请求试试。 |
@shuqingzai Okay, let me try to construct an http request. |
然后使用
gf gen enums
生成boot_enums
并导入进行验证enums 验证报错
1. What version of
Go
and system type/arch are you using?#-> % go version go version go1.21.0 darwin/amd64
2. What version of
GoFrame
are you using?3. Can this issue be re-produced with the latest release?
是的
4. What did you do?
5. What did you expect to see?
6. What did you see instead?
The text was updated successfully, but these errors were encountered: