-
Notifications
You must be signed in to change notification settings - Fork 57
/
replace_prefix_int_enum.go
92 lines (77 loc) · 2.25 KB
/
replace_prefix_int_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
// 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 (
"fmt"
"strings"
)
const (
// AcmeInt_SOME_PLACE_AWESOME is a IntShop of type SOME_PLACE_AWESOME.
AcmeInt_SOME_PLACE_AWESOME IntShop = iota
// AcmeInt_SomewhereElse is a IntShop of type SomewhereElse.
AcmeInt_SomewhereElse
// AcmeInt_LocationUnknown is a IntShop of type LocationUnknown.
AcmeInt_LocationUnknown
)
var ErrInvalidIntShop = fmt.Errorf("not a valid IntShop, try [%s]", strings.Join(_IntShopNames, ", "))
const _IntShopName = "SOME_PLACE_AWESOMESomewhereElseLocationUnknown"
var _IntShopNames = []string{
_IntShopName[0:18],
_IntShopName[18:31],
_IntShopName[31:46],
}
// IntShopNames returns a list of possible string values of IntShop.
func IntShopNames() []string {
tmp := make([]string, len(_IntShopNames))
copy(tmp, _IntShopNames)
return tmp
}
var _IntShopMap = map[IntShop]string{
AcmeInt_SOME_PLACE_AWESOME: _IntShopName[0:18],
AcmeInt_SomewhereElse: _IntShopName[18:31],
AcmeInt_LocationUnknown: _IntShopName[31:46],
}
// String implements the Stringer interface.
func (x IntShop) String() string {
if str, ok := _IntShopMap[x]; ok {
return str
}
return fmt.Sprintf("IntShop(%d)", x)
}
// IsValid provides a quick way to determine if the typed value is
// part of the allowed enumerated values
func (x IntShop) IsValid() bool {
_, ok := _IntShopMap[x]
return ok
}
var _IntShopValue = map[string]IntShop{
_IntShopName[0:18]: AcmeInt_SOME_PLACE_AWESOME,
_IntShopName[18:31]: AcmeInt_SomewhereElse,
_IntShopName[31:46]: AcmeInt_LocationUnknown,
}
// ParseIntShop attempts to convert a string to a IntShop.
func ParseIntShop(name string) (IntShop, error) {
if x, ok := _IntShopValue[name]; ok {
return x, nil
}
return IntShop(0), fmt.Errorf("%s is %w", name, ErrInvalidIntShop)
}
// MarshalText implements the text marshaller method.
func (x IntShop) MarshalText() ([]byte, error) {
return []byte(x.String()), nil
}
// UnmarshalText implements the text unmarshaller method.
func (x *IntShop) UnmarshalText(text []byte) error {
name := string(text)
tmp, err := ParseIntShop(name)
if err != nil {
return err
}
*x = tmp
return nil
}