-
Notifications
You must be signed in to change notification settings - Fork 0
/
bool.go
50 lines (38 loc) · 741 Bytes
/
bool.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Content managed by Project Forge, see [projectforge.md] for details.
package types
import (
"strings"
"admini.dev/admini/app/util"
)
const KeyBool = "bool"
type Bool struct{}
var _ Type = (*Bool)(nil)
func (x *Bool) Key() string {
return KeyBool
}
func (x *Bool) Sortable() bool {
return true
}
func (x *Bool) Scalar() bool {
return true
}
func (x *Bool) String() string {
return x.Key()
}
func (x *Bool) From(v any) any {
switch t := v.(type) {
case bool:
return t
case string:
lt := strings.ToLower(t)
return lt == util.BoolTrue || lt == "yes" || lt == "t"
default:
return invalidInput(x.Key(), t)
}
}
func (x *Bool) Default(string) any {
return false
}
func NewBool() *Wrapped {
return Wrap(&Bool{})
}