Debian Codegraph @

boolean.go

raw
1 package proton
2
3 import "encoding/json"
4
5 // Bool is a convenience type for boolean values; it converts from APIBool to Go's builtin bool type.
6 type Bool bool
7
8 // APIBool is the boolean type used by the API (0 or 1).
9 type APIBool int
10
11 const (
12 APIFalse APIBool = iota
13 APITrue
14 )
15
16 func (b *Bool) UnmarshalJSON(data []byte) error {
17 var v APIBool
18
19 if err := json.Unmarshal(data, &v); err != nil {
20 return err
21 }
22
23 *b = Bool(v == APITrue)
24
25 return nil
26 }
27
28 func (b Bool) MarshalJSON() ([]byte, error) {
29 var v APIBool
30
31 if b {
32 v = APITrue
33 } else {
34 v = APIFalse
35 }
36
37 return json.Marshal(v)
38 }
39
40 func (b Bool) String() string {
41 if b {
42 return "true"
43 }
44
45 return "false"
46 }
47
48 func (b Bool) FormatURL() string {
49 if b {
50 return "1"
51 }
52
53 return "0"
54 }