Skip to content

Commit

Permalink
fix: bool coercer (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
Oudwins authored Aug 21, 2024
1 parent fb60f00 commit 01f8c17
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions conf/Coercers.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@ var Coercers = struct {
Slice CoercerFunc
}{
Bool: func(data any) (any, error) {
if b, ok := data.(bool); ok {
return b, nil
}

switch v := data.(type) {
case bool:
return v, nil
case string:
// There are cases where frontend libraries use "on" as the bool data
// think about toggles. Hence, let's try this first.
Expand All @@ -39,9 +37,17 @@ var Coercers = struct {
}
return boolVal, nil
}
case int:
if v == 0 {
return false, nil
} else if v == 1 {
return true, nil
}
default:
return nil, fmt.Errorf("input data is an unsupported type to coerce to bool: %v", data)
}

return nil, fmt.Errorf("input data is an unsupported type to coerce to bool: %v", data)
},
String: func(data any) (any, error) {
switch v := data.(type) {
Expand Down

0 comments on commit 01f8c17

Please sign in to comment.