-
Notifications
You must be signed in to change notification settings - Fork 0
/
bool.go
51 lines (42 loc) · 814 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
51
package datatypes
import (
"encoding/json"
)
type Bool int
const (
BOOL_UNKNOWN Bool = iota
BOOL_TRUE // true
BOOL_FALSE // false
)
var _ interface {
json.Unmarshaler
json.Marshaler
} = (*Bool)(nil)
func (Bool) OpenAPISchemaType() []string {
return []string{"boolean"}
}
func (v Bool) MarshalJSON() ([]byte, error) {
return v.MarshalText()
}
func (v *Bool) UnmarshalJSON(data []byte) (err error) {
return v.UnmarshalText(data)
}
func (v Bool) MarshalText() ([]byte, error) {
switch v {
case BOOL_FALSE:
return []byte("false"), nil
case BOOL_TRUE:
return []byte("true"), nil
default:
return []byte("null"), nil
}
}
func (v *Bool) UnmarshalText(data []byte) (err error) {
switch string(data) {
case "false":
*v = BOOL_FALSE
case "true":
*v = BOOL_TRUE
}
return
}