-
Notifications
You must be signed in to change notification settings - Fork 62
/
Copy pathcustom_prefix_enum.go
63 lines (52 loc) · 1.47 KB
/
custom_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
// 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"
)
const (
// AcmeIncProductAnvil is a Product of type Anvil.
AcmeIncProductAnvil Product = iota
// AcmeIncProductDynamite is a Product of type Dynamite.
AcmeIncProductDynamite
// AcmeIncProductGlue is a Product of type Glue.
AcmeIncProductGlue
)
var ErrInvalidProduct = errors.New("not a valid Product")
const _ProductName = "AnvilDynamiteGlue"
var _ProductMap = map[Product]string{
AcmeIncProductAnvil: _ProductName[0:5],
AcmeIncProductDynamite: _ProductName[5:13],
AcmeIncProductGlue: _ProductName[13:17],
}
// String implements the Stringer interface.
func (x Product) String() string {
if str, ok := _ProductMap[x]; ok {
return str
}
return fmt.Sprintf("Product(%d)", x)
}
// IsValid provides a quick way to determine if the typed value is
// part of the allowed enumerated values
func (x Product) IsValid() bool {
_, ok := _ProductMap[x]
return ok
}
var _ProductValue = map[string]Product{
_ProductName[0:5]: AcmeIncProductAnvil,
_ProductName[5:13]: AcmeIncProductDynamite,
_ProductName[13:17]: AcmeIncProductGlue,
}
// ParseProduct attempts to convert a string to a Product.
func ParseProduct(name string) (Product, error) {
if x, ok := _ProductValue[name]; ok {
return x, nil
}
return Product(0), fmt.Errorf("%s is %w", name, ErrInvalidProduct)
}