-
Notifications
You must be signed in to change notification settings - Fork 0
/
direction_string.go
105 lines (86 loc) · 2.72 KB
/
direction_string.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// Code generated by "enumer --values --type=Direction --transform=snake --trimprefix=Direction --output direction_string.go --json"; DO NOT EDIT.
package activity
import (
"encoding/json"
"fmt"
"strings"
)
const _DirectionName = "inoutself"
var _DirectionIndex = [...]uint8{0, 2, 5, 9}
const _DirectionLowerName = "inoutself"
func (i Direction) String() string {
i -= 1
if i >= Direction(len(_DirectionIndex)-1) {
return fmt.Sprintf("Direction(%d)", i+1)
}
return _DirectionName[_DirectionIndex[i]:_DirectionIndex[i+1]]
}
func (Direction) Values() []string {
return DirectionStrings()
}
// An "invalid array index" compiler error signifies that the constant values have changed.
// Re-run the stringer command to generate them again.
func _DirectionNoOp() {
var x [1]struct{}
_ = x[DirectionIn-(1)]
_ = x[DirectionOut-(2)]
_ = x[DirectionSelf-(3)]
}
var _DirectionValues = []Direction{DirectionIn, DirectionOut, DirectionSelf}
var _DirectionNameToValueMap = map[string]Direction{
_DirectionName[0:2]: DirectionIn,
_DirectionLowerName[0:2]: DirectionIn,
_DirectionName[2:5]: DirectionOut,
_DirectionLowerName[2:5]: DirectionOut,
_DirectionName[5:9]: DirectionSelf,
_DirectionLowerName[5:9]: DirectionSelf,
}
var _DirectionNames = []string{
_DirectionName[0:2],
_DirectionName[2:5],
_DirectionName[5:9],
}
// DirectionString retrieves an enum value from the enum constants string name.
// Throws an error if the param is not part of the enum.
func DirectionString(s string) (Direction, error) {
if val, ok := _DirectionNameToValueMap[s]; ok {
return val, nil
}
if val, ok := _DirectionNameToValueMap[strings.ToLower(s)]; ok {
return val, nil
}
return 0, fmt.Errorf("%s does not belong to Direction values", s)
}
// DirectionValues returns all values of the enum
func DirectionValues() []Direction {
return _DirectionValues
}
// DirectionStrings returns a slice of all String values of the enum
func DirectionStrings() []string {
strs := make([]string, len(_DirectionNames))
copy(strs, _DirectionNames)
return strs
}
// IsADirection returns "true" if the value is listed in the enum definition. "false" otherwise
func (i Direction) IsADirection() bool {
for _, v := range _DirectionValues {
if i == v {
return true
}
}
return false
}
// MarshalJSON implements the json.Marshaler interface for Direction
func (i Direction) MarshalJSON() ([]byte, error) {
return json.Marshal(i.String())
}
// UnmarshalJSON implements the json.Unmarshaler interface for Direction
func (i *Direction) UnmarshalJSON(data []byte) error {
var s string
if err := json.Unmarshal(data, &s); err != nil {
return fmt.Errorf("Direction should be a string, got %s", data)
}
var err error
*i, err = DirectionString(s)
return err
}