enummap

package
v0.17.19 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 13, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DuplicateKeyError

type DuplicateKeyError string

DuplicateKeyError Duplicate key

func (DuplicateKeyError) Error

func (dk DuplicateKeyError) Error() string

type DuplicateValueError

type DuplicateValueError int

DuplicateValueError Duplicate value

func (DuplicateValueError) Error

func (dv DuplicateValueError) Error() string

type EnumMap

type EnumMap struct {
	// contains filtered or unexported fields
}

EnumMap struct with internal maps containing string and int representations

func New

func New() *EnumMap

New empty enum map

func NewEnumMap

func NewEnumMap(m map[string]int) (*EnumMap, error)

NewEnumMap new enum map from map. Returns error if duplicate values or non-lowercase keys. NewEnumMapOrPanic is preferable for global EnumMap-variables.

func NewEnumMapOrPanic added in v0.5.7

func NewEnumMapOrPanic(m map[string]int) *EnumMap

NewEnumMapOrPanic is intended for assignment to global EnumMap-variables, within global scope or init()-function. When used for global variables NewEnumMapOrPanic fails early, which will be detected by any tests in the same package (even with an empty test file). NewEnumMap is preferable in other cases.

func (*EnumMap) Add

func (em *EnumMap) Add(k string, v int) error

Add entry to EnumMap

func (*EnumMap) AsInt

func (em *EnumMap) AsInt() map[string]int

AsInt returns string to integer map representation of EnumMap

func (*EnumMap) ForEach

func (em *EnumMap) ForEach(f func(k int, v string))

ForEach execute function for each enum entry

func (*EnumMap) ForEachSorted

func (em *EnumMap) ForEachSorted(f func(k int, v string))

ForEachSorted execute function for each enum with strict ordering this is somewhat heavier than using regular ForEach

func (*EnumMap) Int

func (em *EnumMap) Int(s string) (int, error)

Int Get integer representation of enum

func (*EnumMap) Keys

func (em *EnumMap) Keys() []string

func (*EnumMap) String

func (em *EnumMap) String(i int) (string, error)

String Get string representation of enum

func (*EnumMap) StringDefault

func (em *EnumMap) StringDefault(i int, dflt string) string

StringDefault Get string representation of enum or default value

func (*EnumMap) UnMarshal

func (em *EnumMap) UnMarshal(arg []byte) (int, error)

UnMarshal Get int enum representation from byte array

type IntKeyNotFoundError

type IntKeyNotFoundError int

IntKeyNotFoundError Key(int) not found in enum map

func (IntKeyNotFoundError) Error

func (ik IntKeyNotFoundError) Error() string

type NonLowercaseKeyError

type NonLowercaseKeyError string

NonLowercaseKeyError Key contains non-lowercase character

func (NonLowercaseKeyError) Error

func (nlk NonLowercaseKeyError) Error() string

type StringKeyNotFoundError

type StringKeyNotFoundError string

StringKeyNotFoundError Key(string) not found in enum map

func (StringKeyNotFoundError) Error

func (sk StringKeyNotFoundError) Error() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL