-
Notifications
You must be signed in to change notification settings - Fork 124
Closed
Labels
Description
System (please complete the following information):
- OS:
linux - GO Version:
1.21 - Pkg Version:
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 会导致结构体绑定失败。