Added boolean type support for “eq” validator

pull/547/head
Dmitry M. Gavrovsky 5 years ago
parent 691a5f5f25
commit dfc652373a
  1. 5
      baked_in.go
  2. 10
      util.go

@ -1106,6 +1106,11 @@ func isEq(fl FieldLevel) bool {
p := asFloat(param) p := asFloat(param)
return field.Float() == p return field.Float() == p
case reflect.Bool:
p := asBool(param)
return field.Bool() == p
} }
panic(fmt.Sprintf("Bad field type %T", field.Interface())) panic(fmt.Sprintf("Bad field type %T", field.Interface()))

@ -249,6 +249,16 @@ func asFloat(param string) float64 {
return i return i
} }
// asBool returns the parameter as a bool
// or panics if it can't convert
func asBool(param string) bool {
i, err := strconv.ParseBool(param)
panicIf(err)
return i
}
func panicIf(err error) { func panicIf(err error) {
if err != nil { if err != nil {
panic(err.Error()) panic(err.Error())

Loading…
Cancel
Save