const _NumberName = "OneTwoThree" var _NumberIndex = [...]uint8{0, 3, 6, 11} const _NumberLowerName = "onetwothree" func (i Number) String() string { i -= 1 if i < 0 || i >= Number(len(_NumberIndex)-1) { return fmt.Sprintf("Number(%d)", i+1) } return _NumberName[_NumberIndex[i]:_NumberIndex[i+1]] } // ToString converts Number to an int-based string and returns it. func (i Number) ToString() string { return strconv.Itoa(int(i)) } // An "invalid array index" compiler error signifies that the constant values have changed. // Re-run the stringer command to generate them again. func _NumberNoOp() { var x [1]struct{} _ = x[One-(1)] _ = x[Two-(2)] _ = x[Three-(3)] } var _NumberValues = []Number{One, Two, Three} var _NumberNameToValueMap = map[string]Number{ _NumberName[0:3]: One, _NumberLowerName[0:3]: One, _NumberName[3:6]: Two, _NumberLowerName[3:6]: Two, _NumberName[6:11]: Three, _NumberLowerName[6:11]: Three, } var _NumberNames = []string{ _NumberName[0:3], _NumberName[3:6], _NumberName[6:11], } // NumberString retrieves an enum value from the enum constants string name. // Throws an error if the param is not part of the enum. func NumberString(s string) (Number, error) { if val, ok := _NumberNameToValueMap[s]; ok { return val, nil } if val, ok := _NumberNameToValueMap[strings.ToLower(s)]; ok { return val, nil } return 0, fmt.Errorf("%s does not belong to Number values", s) } // NumberValues returns all values of the enum func NumberValues() []Number { return _NumberValues } // NumberStrings returns a slice of all String values of the enum func NumberStrings() []string { strs := make([]string, len(_NumberNames)) copy(strs, _NumberNames) return strs } // IsANumber returns "true" if the value is listed in the enum definition. "false" otherwise func (i Number) IsANumber() bool { for _, v := range _NumberValues { if i == v { return true } } return false }