Documentation
¶
Overview ¶
package enum provides an API for manipulating enumerations.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var AllRepresentations = []Representation{ None, Identifier, Number, }
AllRepresentations lists all 3 values in order.
Functions ¶
func QuotedString ¶
Types ¶
type Enums ¶
type Enums []Enum
Enums is a slice of Enum.
type FloatEnum ¶
FloatEnum is a specialisation for those enums that have float32 or float64 as the underlying type.
type FloatEnums ¶
type FloatEnums []FloatEnum
FloatEnums is a slice of FloatEnum.
func (FloatEnums) Floats ¶
func (es FloatEnums) Floats() []float64
Floats gets the values of the enums in the same order.
func (FloatEnums) Ordinals ¶
func (es FloatEnums) Ordinals() []int
Ordinals gets the ordinal values of the enums in the same order.
func (FloatEnums) Strings ¶
func (es FloatEnums) Strings() []string
Strings gets the string values of the enums in the same order.
type IntEnum ¶
IntEnum is a specialisation for those enums that have int or similar as the underlying type.
type IntEnums ¶
type IntEnums []IntEnum
IntEnums is a slice of IntEnum.
type Representation ¶
type Representation int
const ( None Representation = iota // disables the feature (new in v3) Identifier // uses the main identifier of the corresponding constant Number // the value of the enumerant as a decimal number )
func AsRepresentation ¶
func AsRepresentation(s string) (Representation, error)
AsRepresentation parses a string to find the corresponding Representation, accepting either one of the string values or a number. The input representation is determined by representationMarshalTextRep. It wraps Parse. The input case does not matter.
func MustParseRepresentation ¶
func MustParseRepresentation(s string) Representation
MustParseRepresentation is similar to AsRepresentation except that it panics on error. The input case does not matter.
func RepresentationOf ¶
func RepresentationOf(v int) Representation
RepresentationOf returns a Representation based on an ordinal number. This is the inverse of Ordinal. If the ordinal is out of range, an invalid Representation is returned.
func (Representation) IsValid ¶
func (v Representation) IsValid() bool
IsValid determines whether a Representation is one of the defined constants.
func (Representation) Ordinal ¶
func (v Representation) Ordinal() int
Ordinal returns the ordinal number of a Representation. This is an integer counting from zero. It is *not* the same as the const number assigned to the value.
func (*Representation) Parse ¶
func (v *Representation) Parse(in string) error
Parse parses a string to find the corresponding Representation, accepting one of the string values or a number. The input representation is determined by None. It is used by AsRepresentation. The input case does not matter.
Usage Example
v := new(Representation) err := v.Parse(s) ... etc
func (Representation) String ¶
func (v Representation) String() string
String returns the literal string representation of a Representation, which is the same as the const identifier but without prefix or suffix.