We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
System (please complete the following information):
linux
1.21
1.5.1
Describe the bug
使用 uint filter时,传 null 值会报错 convert value type error。
规则没写 required,前端用的 select 选择,没选的时候会传 null 过来。
To Reproduce
// 类似这样的结构体和规则 type CertStore struct { Type string `form:"type" json:"type"` Domains []string `form:"domains" json:"domains"` AutoRenew bool `form:"auto_renew" json:"auto_renew"` UserID uint `form:"user_id" json:"user_id" filter:"uint"` DNSID uint `form:"dns_id" json:"dns_id" filter:"uint"` WebsiteID uint `form:"website_id" json:"website_id" filter:"uint"` } func (r *CertStore) Rules(ctx http.Context) map[string]string { return map[string]string{ "type": "required|in:P256,P384,2048,4096", "domains": "required|array", "auto_renew": "required|bool", "user_id": "required|uint|exists:cert_users,id", "dns_id": "uint", "website_id": "uint", } }
Expected behavior
传 null 时能正常通过验证。
Screenshots
无
Additional context
如果不使用 filter,则没有这个报错,但是由于 json 自动把数字转成 float64 会导致结构体绑定失败。
The text was updated successfully, but these errors were encountered:
下个版本修复
Sorry, something went wrong.
类型不是限制了 uint 吗?怎么传 null 呢?
类型不是限制了 uint 吗?怎么传 null 呢? 能给下输入json数据示例吗? 还有怎么绑定数据到结构体的
比如前端做了个多选,不选的时候就是null,希望这时候能直接转成uint的0。
null
uint
0
{ "domains": [], "dns_id": null, "type": "P256", "user_id": null, "website_id": null, "auto_renew": true }
website_id这项,没写required。
website_id
required
绑定的报错就是数字被json.Unmarshal解析成float64,然后直接通过github.com/mitchellh/mapstructure无法转换到uint去,这个我已经自行解决。
json.Unmarshal
float64
github.com/mitchellh/mapstructure
✅ test: add a test case for the issues #246
372b694
Please upgrade to https://github.com/gookit/validate/releases/tag/v1.5.2
inhere
No branches or pull requests
System (please complete the following information):
linux
1.21
1.5.1
Describe the bug
使用 uint filter时,传 null 值会报错 convert value type error。
规则没写 required,前端用的 select 选择,没选的时候会传 null 过来。
To Reproduce
Expected behavior
传 null 时能正常通过验证。
Screenshots
无
Additional context
如果不使用 filter,则没有这个报错,但是由于 json 自动把数字转成 float64 会导致结构体绑定失败。
The text was updated successfully, but these errors were encountered: