-
Notifications
You must be signed in to change notification settings - Fork 57
/
negative_enum.go
131 lines (112 loc) · 3.72 KB
/
negative_enum.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// Code generated by go-enum DO NOT EDIT.
// Version: example
// Revision: example
// Build Date: example
// Built By: example
//go:build example
// +build example
package example
import (
"errors"
"fmt"
"strings"
)
const (
// AllNegativeUnknown is a AllNegative of type Unknown.
AllNegativeUnknown AllNegative = iota + -5
// AllNegativeGood is a AllNegative of type Good.
AllNegativeGood
// AllNegativeBad is a AllNegative of type Bad.
AllNegativeBad
// AllNegativeUgly is a AllNegative of type Ugly.
AllNegativeUgly
)
var ErrInvalidAllNegative = errors.New("not a valid AllNegative")
const _AllNegativeName = "UnknownGoodBadUgly"
var _AllNegativeMap = map[AllNegative]string{
AllNegativeUnknown: _AllNegativeName[0:7],
AllNegativeGood: _AllNegativeName[7:11],
AllNegativeBad: _AllNegativeName[11:14],
AllNegativeUgly: _AllNegativeName[14:18],
}
// String implements the Stringer interface.
func (x AllNegative) String() string {
if str, ok := _AllNegativeMap[x]; ok {
return str
}
return fmt.Sprintf("AllNegative(%d)", x)
}
// IsValid provides a quick way to determine if the typed value is
// part of the allowed enumerated values
func (x AllNegative) IsValid() bool {
_, ok := _AllNegativeMap[x]
return ok
}
var _AllNegativeValue = map[string]AllNegative{
_AllNegativeName[0:7]: AllNegativeUnknown,
strings.ToLower(_AllNegativeName[0:7]): AllNegativeUnknown,
_AllNegativeName[7:11]: AllNegativeGood,
strings.ToLower(_AllNegativeName[7:11]): AllNegativeGood,
_AllNegativeName[11:14]: AllNegativeBad,
strings.ToLower(_AllNegativeName[11:14]): AllNegativeBad,
_AllNegativeName[14:18]: AllNegativeUgly,
strings.ToLower(_AllNegativeName[14:18]): AllNegativeUgly,
}
// ParseAllNegative attempts to convert a string to a AllNegative.
func ParseAllNegative(name string) (AllNegative, error) {
if x, ok := _AllNegativeValue[name]; ok {
return x, nil
}
// Case insensitive parse, do a separate lookup to prevent unnecessary cost of lowercasing a string if we don't need to.
if x, ok := _AllNegativeValue[strings.ToLower(name)]; ok {
return x, nil
}
return AllNegative(0), fmt.Errorf("%s is %w", name, ErrInvalidAllNegative)
}
const (
// StatusUnknown is a Status of type Unknown.
StatusUnknown Status = iota + -1
// StatusGood is a Status of type Good.
StatusGood
// StatusBad is a Status of type Bad.
StatusBad
)
var ErrInvalidStatus = errors.New("not a valid Status")
const _StatusName = "UnknownGoodBad"
var _StatusMap = map[Status]string{
StatusUnknown: _StatusName[0:7],
StatusGood: _StatusName[7:11],
StatusBad: _StatusName[11:14],
}
// String implements the Stringer interface.
func (x Status) String() string {
if str, ok := _StatusMap[x]; ok {
return str
}
return fmt.Sprintf("Status(%d)", x)
}
// IsValid provides a quick way to determine if the typed value is
// part of the allowed enumerated values
func (x Status) IsValid() bool {
_, ok := _StatusMap[x]
return ok
}
var _StatusValue = map[string]Status{
_StatusName[0:7]: StatusUnknown,
strings.ToLower(_StatusName[0:7]): StatusUnknown,
_StatusName[7:11]: StatusGood,
strings.ToLower(_StatusName[7:11]): StatusGood,
_StatusName[11:14]: StatusBad,
strings.ToLower(_StatusName[11:14]): StatusBad,
}
// ParseStatus attempts to convert a string to a Status.
func ParseStatus(name string) (Status, error) {
if x, ok := _StatusValue[name]; ok {
return x, nil
}
// Case insensitive parse, do a separate lookup to prevent unnecessary cost of lowercasing a string if we don't need to.
if x, ok := _StatusValue[strings.ToLower(name)]; ok {
return x, nil
}
return Status(0), fmt.Errorf("%s is %w", name, ErrInvalidStatus)
}