const _NumName = "m_2m_1m0m1m2" var _NumIndex = [...]uint8{0, 3, 6, 8, 10, 12} const _NumLowerName = "m_2m_1m0m1m2" func (i Num) string() (string, error) { i -= -2 if i < 0 || i >= Num(len(_NumIndex)-1) { return "", fmt.Errorf("value is out of enum range") } return _NumName[_NumIndex[i]:_NumIndex[i+1]], nil } func (i Num) String() string { val, _ := i.string() return val } func (Num) Values() []string { return NumStrings() } // An "invalid array index" compiler error signifies that the constant values have changed. // Re-run the stringer command to generate them again. func _NumNoOp() { var x [1]struct{} _ = x[m_2-(-2)] _ = x[m_1-(-1)] _ = x[m0-(0)] _ = x[m1-(1)] _ = x[m2-(2)] } var _NumValues = []Num{m_2, m_1, m0, m1, m2} var _NumNameToValueMap = map[string]Num{ _NumName[0:3]: m_2, _NumLowerName[0:3]: m_2, _NumName[3:6]: m_1, _NumLowerName[3:6]: m_1, _NumName[6:8]: m0, _NumLowerName[6:8]: m0, _NumName[8:10]: m1, _NumLowerName[8:10]: m1, _NumName[10:12]: m2, _NumLowerName[10:12]: m2, } var _NumNames = []string{ _NumName[0:3], _NumName[3:6], _NumName[6:8], _NumName[8:10], _NumName[10:12], } // NumString retrieves an enum value from the enum constants string name. // Throws an error if the param is not part of the enum. func NumString(s string) (Num, error) { if val, ok := _NumNameToValueMap[s]; ok { return val, nil } if val, ok := _NumNameToValueMap[strings.ToLower(s)]; ok { return val, nil } return 0, fmt.Errorf("%s does not belong to Num values", s) } // NumValues returns all values of the enum func NumValues() []Num { return _NumValues } // NumStrings returns a slice of all String values of the enum func NumStrings() []string { strs := make([]string, len(_NumNames)) copy(strs, _NumNames) return strs } // IsANum returns "true" if the value is listed in the enum definition. "false" otherwise func (i Num) IsANum() bool { for _, v := range _NumValues { if i == v { return true } } return false }