You are viewing an old version of this page. View the current version.
Compare with Current View Page History
Version 9 Current »
Struct
required
Struct的属性会有默认值,在某些情况下会引起required规则的失效。例如:
默认值
type User struct { Name string `v:"required"` Age uint `v:"required"` }
在该结构体校验中,Age属性的required校验将会失效,因为Age即便没有输入也会有默认值0。
Age
0
这里有三种解决方案:
Assoc
Server
API
XxxReq/XxxRes
required|min:1
*int
*float64
*g.Var
nil