Skip to content

Commit dfc6523

Browse files
committed
Added boolean type support for “eq” validator
1 parent 691a5f5 commit dfc6523

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

baked_in.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,6 +1106,11 @@ func isEq(fl FieldLevel) bool {
11061106
p := asFloat(param)
11071107

11081108
return field.Float() == p
1109+
1110+
case reflect.Bool:
1111+
p := asBool(param)
1112+
1113+
return field.Bool() == p
11091114
}
11101115

11111116
panic(fmt.Sprintf("Bad field type %T", field.Interface()))

util.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,16 @@ func asFloat(param string) float64 {
249249
return i
250250
}
251251

252+
// asBool returns the parameter as a bool
253+
// or panics if it can't convert
254+
func asBool(param string) bool {
255+
256+
i, err := strconv.ParseBool(param)
257+
panicIf(err)
258+
259+
return i
260+
}
261+
252262
func panicIf(err error) {
253263
if err != nil {
254264
panic(err.Error())

0 commit comments

Comments
 (0)