-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtype_enumer.go
More file actions
94 lines (79 loc) · 2.21 KB
/
type_enumer.go
File metadata and controls
94 lines (79 loc) · 2.21 KB
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
// Code generated by "enumer -type Type"; DO NOT EDIT.
package msg
import (
"fmt"
"strings"
)
const _TypeName = "INVALIDOPENUPDATENOTIFYKEEPALIVEREFRESH"
var _TypeIndex = [...]uint8{0, 7, 11, 17, 23, 32, 39}
const _TypeLowerName = "invalidopenupdatenotifykeepaliverefresh"
func (i Type) String() string {
if i >= Type(len(_TypeIndex)-1) {
return fmt.Sprintf("Type(%d)", i)
}
return _TypeName[_TypeIndex[i]:_TypeIndex[i+1]]
}
// An "invalid array index" compiler error signifies that the constant values have changed.
// Re-run the stringer command to generate them again.
func _TypeNoOp() {
var x [1]struct{}
_ = x[INVALID-(0)]
_ = x[OPEN-(1)]
_ = x[UPDATE-(2)]
_ = x[NOTIFY-(3)]
_ = x[KEEPALIVE-(4)]
_ = x[REFRESH-(5)]
}
var _TypeValues = []Type{INVALID, OPEN, UPDATE, NOTIFY, KEEPALIVE, REFRESH}
var _TypeNameToValueMap = map[string]Type{
_TypeName[0:7]: INVALID,
_TypeLowerName[0:7]: INVALID,
_TypeName[7:11]: OPEN,
_TypeLowerName[7:11]: OPEN,
_TypeName[11:17]: UPDATE,
_TypeLowerName[11:17]: UPDATE,
_TypeName[17:23]: NOTIFY,
_TypeLowerName[17:23]: NOTIFY,
_TypeName[23:32]: KEEPALIVE,
_TypeLowerName[23:32]: KEEPALIVE,
_TypeName[32:39]: REFRESH,
_TypeLowerName[32:39]: REFRESH,
}
var _TypeNames = []string{
_TypeName[0:7],
_TypeName[7:11],
_TypeName[11:17],
_TypeName[17:23],
_TypeName[23:32],
_TypeName[32:39],
}
// TypeString retrieves an enum value from the enum constants string name.
// Throws an error if the param is not part of the enum.
func TypeString(s string) (Type, error) {
if val, ok := _TypeNameToValueMap[s]; ok {
return val, nil
}
if val, ok := _TypeNameToValueMap[strings.ToLower(s)]; ok {
return val, nil
}
return 0, fmt.Errorf("%s does not belong to Type values", s)
}
// TypeValues returns all values of the enum
func TypeValues() []Type {
return _TypeValues
}
// TypeStrings returns a slice of all String values of the enum
func TypeStrings() []string {
strs := make([]string, len(_TypeNames))
copy(strs, _TypeNames)
return strs
}
// IsAType returns "true" if the value is listed in the enum definition. "false" otherwise
func (i Type) IsAType() bool {
for _, v := range _TypeValues {
if i == v {
return true
}
}
return false
}