diff --git a/baked_in.go b/baked_in.go index 23f76b3..f80c315 100644 --- a/baked_in.go +++ b/baked_in.go @@ -1106,6 +1106,11 @@ func isEq(fl FieldLevel) bool { p := asFloat(param) return field.Float() == p + + case reflect.Bool: + p := asBool(param) + + return field.Bool() == p } panic(fmt.Sprintf("Bad field type %T", field.Interface())) diff --git a/util.go b/util.go index 71acbdc..0d3a181 100644 --- a/util.go +++ b/util.go @@ -249,6 +249,16 @@ func asFloat(param string) float64 { 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) { if err != nil { panic(err.Error())