-
Notifications
You must be signed in to change notification settings - Fork 1
/
kind_enumer.go
115 lines (95 loc) · 2.67 KB
/
kind_enumer.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
106
107
108
109
110
111
112
113
114
115
// Code generated by "enumer -type=Kind -text -yaml"; DO NOT EDIT.
package main
import (
"fmt"
"strings"
)
const _KindName = "StringBoolFloatInteger"
var _KindIndex = [...]uint8{0, 6, 10, 15, 22}
const _KindLowerName = "stringboolfloatinteger"
func (i Kind) String() string {
if i < 0 || i >= Kind(len(_KindIndex)-1) {
return fmt.Sprintf("Kind(%d)", i)
}
return _KindName[_KindIndex[i]:_KindIndex[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 _KindNoOp() {
var x [1]struct{}
_ = x[String-(0)]
_ = x[Bool-(1)]
_ = x[Float-(2)]
_ = x[Integer-(3)]
}
var _KindValues = []Kind{String, Bool, Float, Integer}
var _KindNameToValueMap = map[string]Kind{
_KindName[0:6]: String,
_KindLowerName[0:6]: String,
_KindName[6:10]: Bool,
_KindLowerName[6:10]: Bool,
_KindName[10:15]: Float,
_KindLowerName[10:15]: Float,
_KindName[15:22]: Integer,
_KindLowerName[15:22]: Integer,
}
var _KindNames = []string{
_KindName[0:6],
_KindName[6:10],
_KindName[10:15],
_KindName[15:22],
}
// KindString retrieves an enum value from the enum constants string name.
// Throws an error if the param is not part of the enum.
func KindString(s string) (Kind, error) {
if val, ok := _KindNameToValueMap[s]; ok {
return val, nil
}
if val, ok := _KindNameToValueMap[strings.ToLower(s)]; ok {
return val, nil
}
return 0, fmt.Errorf("%s does not belong to Kind values", s)
}
// KindValues returns all values of the enum
func KindValues() []Kind {
return _KindValues
}
// KindStrings returns a slice of all String values of the enum
func KindStrings() []string {
strs := make([]string, len(_KindNames))
copy(strs, _KindNames)
return strs
}
// IsAKind returns "true" if the value is listed in the enum definition. "false" otherwise
func (i Kind) IsAKind() bool {
for _, v := range _KindValues {
if i == v {
return true
}
}
return false
}
// MarshalText implements the encoding.TextMarshaler interface for Kind
func (i Kind) MarshalText() ([]byte, error) {
return []byte(i.String()), nil
}
// UnmarshalText implements the encoding.TextUnmarshaler interface for Kind
func (i *Kind) UnmarshalText(text []byte) error {
var err error
*i, err = KindString(string(text))
return err
}
// MarshalYAML implements a YAML Marshaler for Kind
func (i Kind) MarshalYAML() (interface{}, error) {
return i.String(), nil
}
// UnmarshalYAML implements a YAML Unmarshaler for Kind
func (i *Kind) UnmarshalYAML(unmarshal func(interface{}) error) error {
var s string
if err := unmarshal(&s); err != nil {
return err
}
var err error
*i, err = KindString(s)
return err
}