-
Notifications
You must be signed in to change notification settings - Fork 57
/
replace_prefix_enum.go
80 lines (67 loc) · 1.94 KB
/
replace_prefix_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
// 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 (
// AcmeInc_SOME_PLACE_AWESOME is a Shop of type SOME_PLACE_AWESOME.
AcmeInc_SOME_PLACE_AWESOME Shop = "SOME_PLACE_AWESOME"
// AcmeInc_SomewhereElse is a Shop of type SomewhereElse.
AcmeInc_SomewhereElse Shop = "SomewhereElse"
// AcmeInc_LocationUnknown is a Shop of type LocationUnknown.
AcmeInc_LocationUnknown Shop = "LocationUnknown"
)
var ErrInvalidShop = fmt.Errorf("not a valid Shop, try [%s]", strings.Join(_ShopNames, ", "))
var _ShopNames = []string{
string(AcmeInc_SOME_PLACE_AWESOME),
string(AcmeInc_SomewhereElse),
string(AcmeInc_LocationUnknown),
}
// ShopNames returns a list of possible string values of Shop.
func ShopNames() []string {
tmp := make([]string, len(_ShopNames))
copy(tmp, _ShopNames)
return tmp
}
// String implements the Stringer interface.
func (x Shop) String() string {
return string(x)
}
// IsValid provides a quick way to determine if the typed value is
// part of the allowed enumerated values
func (x Shop) IsValid() bool {
_, err := ParseShop(string(x))
return err == nil
}
var _ShopValue = map[string]Shop{
"SOME_PLACE_AWESOME": AcmeInc_SOME_PLACE_AWESOME,
"SomewhereElse": AcmeInc_SomewhereElse,
"LocationUnknown": AcmeInc_LocationUnknown,
}
// ParseShop attempts to convert a string to a Shop.
func ParseShop(name string) (Shop, error) {
if x, ok := _ShopValue[name]; ok {
return x, nil
}
return Shop(""), fmt.Errorf("%s is %w", name, ErrInvalidShop)
}
// MarshalText implements the text marshaller method.
func (x Shop) MarshalText() ([]byte, error) {
return []byte(string(x)), nil
}
// UnmarshalText implements the text unmarshaller method.
func (x *Shop) UnmarshalText(text []byte) error {
tmp, err := ParseShop(string(text))
if err != nil {
return err
}
*x = tmp
return nil
}