2020-03-14 15:13:38 +00:00
|
|
|
package builtin
|
|
|
|
|
2020-03-16 08:20:00 +00:00
|
|
|
import "git.xdrm.io/go/aicra/datatype"
|
2020-03-14 15:13:38 +00:00
|
|
|
|
|
|
|
// BoolDataType is what its name tells
|
|
|
|
type BoolDataType struct{}
|
|
|
|
|
|
|
|
// Build returns the validator
|
|
|
|
func (BoolDataType) Build(typeName string) datatype.Validator {
|
|
|
|
// nothing if type not handled
|
|
|
|
if typeName != "bool" {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return func(value interface{}) (interface{}, bool) {
|
|
|
|
switch cast := value.(type) {
|
|
|
|
case bool:
|
|
|
|
return cast, true
|
|
|
|
|
|
|
|
case string:
|
|
|
|
strVal := string(cast)
|
|
|
|
return strVal == "true", strVal == "true" || strVal == "false"
|
|
|
|
case []byte:
|
|
|
|
strVal := string(cast)
|
|
|
|
return strVal == "true", strVal == "true" || strVal == "false"
|
|
|
|
|
|
|
|
default:
|
|
|
|
return false, false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|