forked from abice/go-enum
-
Notifications
You must be signed in to change notification settings - Fork 0
/
custom_prefix_enum.go
47 lines (39 loc) · 1010 Bytes
/
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
// Code generated by go-enum
// DO NOT EDIT!
package example
import (
"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
)
const _ProductName = "AnvilDynamiteGlue"
var _ProductMap = map[Product]string{
0: _ProductName[0:5],
1: _ProductName[5:13],
2: _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)
}
var _ProductValue = map[string]Product{
_ProductName[0:5]: 0,
_ProductName[5:13]: 1,
_ProductName[13:17]: 2,
}
// 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 not a valid Product", name)
}