validator
validator copied to clipboard
unique tag panic on slice contains nil elem
i want to make sure elem of pointer slice is not nil,meanwhile, i also need the Name field is unique.
the former can be achieved like:
struct {
F1 []*A validate:"dive,required"
}
however, the unique tag on nil elem cause panic
func TestName(t *testing.T) {
type A struct {
Name string
}
e := struct {
F1 []*A validate:"unique=Name"
}{F1: []*A{nil}}
err := validate.Struct(e)
assert.Error(t, err)
}
it turns out: panic: reflect: call of reflect.Value.FieldByName on zero Value [recovered] panic: reflect: call of reflect.Value.FieldByName on zero Value
Your expectation is that a nil entry in the list would also fail validation, right?