25 lines
407 B
Go
25 lines
407 B
Go
package validation
|
|
|
|
import (
|
|
"fmt"
|
|
"strconv"
|
|
)
|
|
|
|
type BoolField struct {
|
|
FieldBase
|
|
Value bool
|
|
}
|
|
|
|
func newBoolField(key string, g Getter) *BoolField {
|
|
raw := g.Get(key)
|
|
val, err := strconv.ParseBool(raw)
|
|
if err != nil {
|
|
g.AddCheck(newFailedCheck("Invalid boolean value",
|
|
fmt.Sprintf("Field %s requires a boolean value, %s given", key, raw)))
|
|
}
|
|
return &BoolField{
|
|
newField(key, g),
|
|
val,
|
|
}
|
|
}
|