Documentation ¶
Index ¶
- func EnumNames[T EnumDefinition](enums ...T) (names []string)
- func GetEnumMap[T EnumDefinition]() map[string]T
- func GetEnums[T EnumDefinition](names ...string) (res []T, valid bool)
- func IsValidEnum[T EnumDefinition](name string) (valid bool)
- func NewEnum[T EnumDefinition](name string, src ...T) T
- func Size[T EnumDefinition]() int
- func Unmarshal[T EnumDefinition](data []byte) (t T, err error)
- func ValueOf[T EnumDefinition](name string) (t T, valid bool)
- func ValueOfIgnoreCase[T EnumDefinition](name string) (t T, valid bool)
- func Values[T EnumDefinition]() []T
- type Enum
- func (e Enum) Compare(other EnumDefinition) int
- func (e Enum) Equals(other EnumDefinition) bool
- func (e Enum) MarshalJSON() ([]byte, error)
- func (e Enum) MarshalText() (text []byte, err error)
- func (e Enum) Name() string
- func (e Enum) Ordinal() int
- func (e Enum) String() string
- func (e Enum) Type() string
- type EnumDefinition
- type EnumSet
- type UnsafeEnumSet
- func (set *UnsafeEnumSet[E]) Add(e E) bool
- func (set *UnsafeEnumSet[E]) AddRange(begin, end E) int
- func (set *UnsafeEnumSet[E]) Clear()
- func (set *UnsafeEnumSet[E]) Clone() EnumSet[E]
- func (set *UnsafeEnumSet[E]) Contains(enums ...E) bool
- func (set *UnsafeEnumSet[E]) ContainsAll(enumSet EnumSet[E]) bool
- func (set *UnsafeEnumSet[E]) Each(f func(e E) bool)
- func (set *UnsafeEnumSet[E]) Equals(enumSet EnumSet[E]) bool
- func (set *UnsafeEnumSet[E]) IsEmpty() bool
- func (set *UnsafeEnumSet[E]) Len() int
- func (set *UnsafeEnumSet[E]) MarshalJSON() ([]byte, error)
- func (set *UnsafeEnumSet[E]) Names() []string
- func (set *UnsafeEnumSet[E]) Remove(e E) bool
- func (set *UnsafeEnumSet[E]) RemoveRange(begin, end E) int
- func (set *UnsafeEnumSet[E]) String() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EnumNames ¶
func EnumNames[T EnumDefinition](enums ...T) (names []string)
EnumNames Get the names of a batch of enumerations. If no instances are passed in, return the Name value of all enumeration instances of the type specified by the generic parameter.
func GetEnumMap ¶
func GetEnumMap[T EnumDefinition]() map[string]T
GetEnumMap Get all enumeration instances of the specified type. The key is the Name of the enumeration instance, and the value is the enumeration instance.
func GetEnums ¶ added in v1.2.0
func GetEnums[T EnumDefinition](names ...string) (res []T, valid bool)
GetEnums Obtain a batch of enumeration instances based on the enumeration name list
func IsValidEnum ¶
func IsValidEnum[T EnumDefinition](name string) (valid bool)
IsValidEnum Determine if the incoming string is a valid enumeration
func NewEnum ¶
func NewEnum[T EnumDefinition](name string, src ...T) T
NewEnum Create a new enumeration. If an enumeration instance with the same Type and Name already exists, the current method will throw a panic to prevent duplicate enumeration creation
func Size ¶ added in v1.1.0
func Size[T EnumDefinition]() int
Size Number of instances of specified enumeration type
func Unmarshal ¶ added in v1.2.1
func Unmarshal[T EnumDefinition](data []byte) (t T, err error)
Unmarshal Deserialize the enumeration instance from the JSON string, and return an error if not found
func ValueOf ¶
func ValueOf[T EnumDefinition](name string) (t T, valid bool)
ValueOf Find an enumeration instance based on the string, and return a zero value if not found
func ValueOfIgnoreCase ¶
func ValueOfIgnoreCase[T EnumDefinition](name string) (t T, valid bool)
ValueOfIgnoreCase Ignoring case to obtain enumeration instances. Note: This method involves one reflection call, and its performance is slightly worse than the ValueOf method
func Values ¶
func Values[T EnumDefinition]() []T
Values Return all enumeration instances. The returned slice are sorted by ordinal
Types ¶
type Enum ¶
type Enum struct {
// contains filtered or unexported fields
}
func (Enum) Compare ¶
func (e Enum) Compare(other EnumDefinition) int
func (Enum) Equals ¶
func (e Enum) Equals(other EnumDefinition) bool
func (Enum) MarshalJSON ¶
func (Enum) MarshalText ¶ added in v1.2.0
type EnumDefinition ¶
type EnumDefinition interface { fmt.Stringer json.Marshaler encoding.TextMarshaler // Name The name of the enumeration. The enumeration names of the same Type must be unique. Name() string // Equals Compare with another enumeration. Only return true if both Type and Name are the same Equals(other EnumDefinition) bool // Type String representation of enumeration type Type() string // Ordinal Get the ordinal of the enumeration, starting from zero and increasing in declared order. Ordinal() int // Compare -Compare with the ordinal value of another enumeration Compare(other EnumDefinition) int }
type EnumSet ¶ added in v1.1.0
type EnumSet[E EnumDefinition] interface { fmt.Stringer json.Marshaler // Add -Add an element to Set. If successful, return true. If it already exists, return false Add(e E) bool // AddRange According to the ordinal of the enumeration, // add a continuous section of the enumeration and // return the actual number added (excluding those that already exist) AddRange(begin, end E) int // Remove Delete element. If the deletion is successful, return true. // If the element does not exist, return false Remove(e E) bool // RemoveRange According to the ordinal of the enumeration, // continuously delete a segment of the enumeration and // return the actual number of deletions (excluding those that non-exist) RemoveRange(begin, end E) int // IsEmpty Is Set empty IsEmpty() bool // Clear -Clear set Clear() // Len The current number of enumeration instances within the Set Len() int // Contains Does it contain the specified enumeration? // Returns false if there is only one that does not exist in the Set Contains(enums ...E) bool // ContainsAll Determine if it contains another enumSet (subset relationship) ContainsAll(set EnumSet[E]) bool // Equals Determine if two EnumSets are the same Equals(set EnumSet[E]) bool // Each Set iteration method, if f method returns false, abort iteration Each(f func(e E) bool) // Names Returns the Name representation of an existing enumeration instance in the set Names() []string // Clone Deep copy to obtain a new set Clone() EnumSet[E] }
EnumSet Enumerate sets. Usually used for high-performance lookup when there are many instances of a certain type of enumeration.
type UnsafeEnumSet ¶ added in v1.1.0
type UnsafeEnumSet[E EnumDefinition] struct { // contains filtered or unexported fields }
func NewUnsafeEnumSet ¶ added in v1.1.0
func NewUnsafeEnumSet[E EnumDefinition]() *UnsafeEnumSet[E]
func (*UnsafeEnumSet[E]) Add ¶ added in v1.1.0
func (set *UnsafeEnumSet[E]) Add(e E) bool
func (*UnsafeEnumSet[E]) AddRange ¶ added in v1.1.0
func (set *UnsafeEnumSet[E]) AddRange(begin, end E) int
func (*UnsafeEnumSet[E]) Clear ¶ added in v1.1.0
func (set *UnsafeEnumSet[E]) Clear()
func (*UnsafeEnumSet[E]) Clone ¶ added in v1.1.0
func (set *UnsafeEnumSet[E]) Clone() EnumSet[E]
func (*UnsafeEnumSet[E]) Contains ¶ added in v1.1.0
func (set *UnsafeEnumSet[E]) Contains(enums ...E) bool
func (*UnsafeEnumSet[E]) ContainsAll ¶ added in v1.1.0
func (set *UnsafeEnumSet[E]) ContainsAll(enumSet EnumSet[E]) bool
func (*UnsafeEnumSet[E]) Each ¶ added in v1.1.0
func (set *UnsafeEnumSet[E]) Each(f func(e E) bool)
func (*UnsafeEnumSet[E]) Equals ¶ added in v1.1.0
func (set *UnsafeEnumSet[E]) Equals(enumSet EnumSet[E]) bool
func (*UnsafeEnumSet[E]) IsEmpty ¶ added in v1.1.0
func (set *UnsafeEnumSet[E]) IsEmpty() bool
func (*UnsafeEnumSet[E]) Len ¶ added in v1.1.0
func (set *UnsafeEnumSet[E]) Len() int
func (*UnsafeEnumSet[E]) MarshalJSON ¶ added in v1.1.0
func (set *UnsafeEnumSet[E]) MarshalJSON() ([]byte, error)
func (*UnsafeEnumSet[E]) Names ¶ added in v1.1.0
func (set *UnsafeEnumSet[E]) Names() []string
func (*UnsafeEnumSet[E]) Remove ¶ added in v1.1.0
func (set *UnsafeEnumSet[E]) Remove(e E) bool
func (*UnsafeEnumSet[E]) RemoveRange ¶ added in v1.1.0
func (set *UnsafeEnumSet[E]) RemoveRange(begin, end E) int
func (*UnsafeEnumSet[E]) String ¶ added in v1.1.0
func (set *UnsafeEnumSet[E]) String() string