...
1
2
3 package Example
4
5 import "strconv"
6
7
8 type Color byte
9
10 const (
11 ColorRed Color = 1
12
13
14 ColorGreen Color = 2
15
16 ColorBlue Color = 8
17 )
18
19 var EnumNamesColor = map[Color]string{
20 ColorRed: "Red",
21 ColorGreen: "Green",
22 ColorBlue: "Blue",
23 }
24
25 var EnumValuesColor = map[string]Color{
26 "Red": ColorRed,
27 "Green": ColorGreen,
28 "Blue": ColorBlue,
29 }
30
31 func (v Color) String() string {
32 if s, ok := EnumNamesColor[v]; ok {
33 return s
34 }
35 return "Color(" + strconv.FormatInt(int64(v), 10) + ")"
36 }
37
View as plain text