5
                            对于递归校验,即使外层没有 required 也会递归到底层
func Test_Validation(t *testing.T) {
    ctx := context.Background()
    gtest.C(t, func(t *gtest.T) {
        type Student struct {
            Name string `v:"required"`
            Age  int
        }
        type Teacher struct {
            Students Student
        }
        var (
            teacher = Teacher{}
            data    = g.Map{
                "students": nil,
            }
        )
        err := g.Validator().Assoc(data).Data(teacher).Run(ctx)
        fmt.Println(err)
    })
}而且,只要我有了同名的字段,即使不在结构体对应的层级上,也会校验通过
func Test_Validation(t *testing.T) {
    ctx := context.Background()
    gtest.C(t, func(t *gtest.T) {
        type Student struct {
            Name string `v:"required"`
        }
        type Teacher struct {
            Students Student
        }
        var (
            teacher = Teacher{}
            data    = g.Map{
                "name":     "john",   // 不在对应的层级上,但是校验通过了
                "students": nil,
            }
        )
        err := g.Validator().Assoc(data).Data(teacher).Run(ctx)
        fmt.Println(err)
    })
}不用校验内部的 Name