Documentation
¶
Index ¶
- func Enums[T Enumer[T]]() []T
- func Names[T Enumer[T]]() []string
- func Parse[T Enumer[T]](name string) (T, error)
- func SetOptions(options ...Option)
- func Strings[T Enumer[T]]() []string
- func Type[T Enumer[T]]() string
- func Values[T Enumer[T]]() []int
- type Enum
- func (e Enum[T]) Enums() []Enum[T]
- func (e Enum[T]) MarshalText() ([]byte, error)
- func (e Enum[T]) Name() string
- func (e Enum[T]) Names() []string
- func (e Enum[T]) Parse(name string) (Enum[T], error)
- func (e Enum[T]) String() string
- func (e Enum[T]) Strings() []string
- func (e Enum[T]) Type() string
- func (e *Enum[T]) UnmarshalText(text []byte) error
- func (e Enum[T]) Values() []int
- type Enumer
- type Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Enums ¶
func Enums[T Enumer[T]]() []T
Enums is a static function to handel all enums that implements Enumer[T] interface. It returns a list of all Enum[T] declarations mapped to T.
func Names ¶
Names is a static function to handel all enums that implements Enumer[T] interface. It returns a list of all Enum[T] names. (the programmatic string representation of the enum value).
func Parse ¶
Parse is a static function to handel all enums that implements Enumer[T] interface. It will try to parse the given name with the underline Enum.Parse implementation.
func SetOptions ¶ added in v1.0.0
func SetOptions(options ...Option)
SetOptions Sets multiple Option on the global scope.
func Strings ¶ added in v0.2.1
Strings is a static function to handel all enums that implements Enumer[T] interface. It returns a list of all Enum[T] strings.
Types ¶
type Enum ¶
Enum uses T struct definition for it's mapping of enum name to value.
func (Enum[T]) MarshalText ¶
MarshalText implements the TextMarshaler interface for T.
func (Enum[T]) Names ¶
Names returns all the Enum[T] programmatic string representations sorted by the enum values.
func (Enum[T]) Parse ¶
Parse tries to parse an enum name based on the underline enum name to enum value mapping. If CaseInsensitive(true) is set, Parse will use the lowered case name to value mapping instead.
func (Enum[T]) Strings ¶ added in v0.2.1
Strings returns all the Enum[T] string representations sorted by the enum values.
func (*Enum[T]) UnmarshalText ¶ added in v0.1.1
UnmarshalText implements the TextUnmarshaler interface for T.
type Enumer ¶
type Enumer[T ~int] interface { ~int Enums() []T Name() string Names() []string Parse(name string) (T, error) String() string Strings() []string Type() string Values() []int }
Enumer is an interface for using Enum instances with generics, e.g, `func foo[T Enumer[T]](enum T)` could do any Enum operations while preserving the original Enum type (T)
type Option ¶ added in v1.0.0
type Option func(config *config)
Option callback function that sets specific value on an *config instance.
func CaseInsensitive ¶ added in v0.2.1
CaseInsensitive - when set to true, Enum.Parse and Enum.UnmarshalText, will ignore the string case when parsing.
func ParseCallback ¶ added in v0.2.1
ParseCallback will be applied for each Enum.Parse call and Enum.UnmarshalText.
func StringCallback ¶ added in v0.2.1
StringCallback will be applied for each Enum.String call and Enum.Strings.