You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
The text was updated successfully, but these errors were encountered:
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
The text was updated successfully, but these errors were encountered: