可选校验规则
示例1,空字符串
示例2,空指针属性
package main
import (
"fmt"
"github.com/gogf/gf/v2/container/gvar"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gctx"
)
func main() {
Page int `v:"required|min:1 # page is required"`
Size int `v:"required|between:1,100 # size is required"`
ProjectId *gvar.Var `v:"between:1,10000 # project id must between {min}, {max}"`
}
var (
ctx = gctx.New()
obj = &Params{
Page: 1,
Size: 10,
}
err := g.Validator().Data(obj).Run(ctx)
fmt.Println(err)
// Output:
// <nil>
}
示例3,空整型属性
project id must between 1, 10000
示例4,通过map
传参
{
"password": {
"same": "The password value `123456` must be the same as field password2",
}