-
Notifications
You must be signed in to change notification settings - Fork 57
/
animal_enum.go
71 lines (60 loc) · 1.62 KB
/
animal_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
// 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 (
// AnimalCat is a Animal of type Cat.
AnimalCat Animal = iota
// AnimalDog is a Animal of type Dog.
AnimalDog
// AnimalFish is a Animal of type Fish.
AnimalFish
// AnimalFishPlusPlus is a Animal of type Fish++.
AnimalFishPlusPlus
// AnimalFishSharp is a Animal of type Fish#.
AnimalFishSharp
)
var ErrInvalidAnimal = errors.New("not a valid Animal")
const _AnimalName = "CatDogFishFish++Fish#"
var _AnimalMap = map[Animal]string{
AnimalCat: _AnimalName[0:3],
AnimalDog: _AnimalName[3:6],
AnimalFish: _AnimalName[6:10],
AnimalFishPlusPlus: _AnimalName[10:16],
AnimalFishSharp: _AnimalName[16:21],
}
// String implements the Stringer interface.
func (x Animal) String() string {
if str, ok := _AnimalMap[x]; ok {
return str
}
return fmt.Sprintf("Animal(%d)", x)
}
// IsValid provides a quick way to determine if the typed value is
// part of the allowed enumerated values
func (x Animal) IsValid() bool {
_, ok := _AnimalMap[x]
return ok
}
var _AnimalValue = map[string]Animal{
_AnimalName[0:3]: AnimalCat,
_AnimalName[3:6]: AnimalDog,
_AnimalName[6:10]: AnimalFish,
_AnimalName[10:16]: AnimalFishPlusPlus,
_AnimalName[16:21]: AnimalFishSharp,
}
// ParseAnimal attempts to convert a string to a Animal.
func ParseAnimal(name string) (Animal, error) {
if x, ok := _AnimalValue[name]; ok {
return x, nil
}
return Animal(0), fmt.Errorf("%s is %w", name, ErrInvalidAnimal)
}