Open DarkReduX opened 2 years ago
Up. ran into the same problem.
My temp resolve:
func omitnilLtefield(fl validator.FieldLevel) bool {
f := fl.Field()
f2 := fl.Parent().FieldByName(fl.Param())
if f2.Kind() == reflect.Pointer && f2.IsNil() || f.IsZero() || f2.IsZero() {
return true
}
switch f.Kind() { //nolint:exhaustive
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
return f.Int() <= f2.Elem().Int()
case reflect.Float32, reflect.Float64:
return f.Float() <= f2.Elem().Float()
}
return true
}
validate.RegisterValidation("omitnil_ltefield", omitnilLtefield)
Package version eg. v10:
Issue, Question or Enhancement:
Got fail on validate:"ltfield" tag when use pointers on struct fields and one of them is nil
Code sample, to showcase or reproduce: