Documentation ¶
Index ¶
- func GetTyped[T any](m map[string]any, key string) T
- func GetTypedOr[T any](m map[string]any, key string, defaultVal T) T
- type Map
- func (p Map) Get(key string) (value any, exists bool)
- func (p Map) GetBool(key string) bool
- func (p Map) GetBytes(key string) []byte
- func (p Map) GetDuration(key string) time.Duration
- func (p Map) GetFloat(key string) float64
- func (p Map) GetInt(key string) int
- func (p Map) GetInt32(key string) int32
- func (p Map) GetInt32s(key string) []int32
- func (p Map) GetInt64(key string) int64
- func (p Map) GetInt64s(key string) []int64
- func (p Map) GetMap(key string) Map
- func (p Map) GetOr(key string, defaultVal any) (value any)
- func (p Map) GetSlice(key string) any
- func (p Map) GetString(key string) string
- func (p Map) GetStringMap(key string) map[string]string
- func (p Map) GetStrings(key string) []string
- func (p Map) GetTime(key string) time.Time
- func (p Map) GetUint(key string) uint
- func (p Map) GetUint32(key string) uint32
- func (p Map) GetUint64(key string) uint64
- func (p Map) Iterate(fn func(k string, v any) int)
- func (p Map) MarshalJSON() ([]byte, error)
- func (p Map) MarshalJSONPretty() ([]byte, error)
- func (p Map) MarshalYAML() (any, error)
- func (p *Map) Merge(other map[string]any)
- func (p Map) MustGet(key string) any
- func (p *Map) Set(key string, value any)
- func (p *Map) UnmarshalJSON(data []byte) error
- func (p *Map) UnmarshalYAML(value *yaml.Node) error
- type SafeMap
- func (p *SafeMap) Get(key string) (value any, exists bool)
- func (p *SafeMap) GetBool(key string) bool
- func (p *SafeMap) GetBytes(key string) []byte
- func (p *SafeMap) GetDuration(key string) time.Duration
- func (p *SafeMap) GetFloat(key string) float64
- func (p *SafeMap) GetInt(key string) int
- func (p *SafeMap) GetInt32(key string) int32
- func (p *SafeMap) GetInt32s(key string) []int32
- func (p *SafeMap) GetInt64(key string) int64
- func (p *SafeMap) GetInt64s(key string) []int64
- func (p *SafeMap) GetMap(key string) Map
- func (p *SafeMap) GetOr(key string, defaultVal any) (value any)
- func (p *SafeMap) GetSlice(key string) any
- func (p *SafeMap) GetString(key string) string
- func (p *SafeMap) GetStringMap(key string) map[string]string
- func (p *SafeMap) GetStrings(key string) []string
- func (p *SafeMap) GetTime(key string) time.Time
- func (p *SafeMap) GetUint(key string) uint
- func (p *SafeMap) GetUint32(key string) uint32
- func (p *SafeMap) GetUint64(key string) uint64
- func (p *SafeMap) Iterate(fn func(k string, v any) int)
- func (p *SafeMap) MarshalJSON() ([]byte, error)
- func (p *SafeMap) MarshalJSONPretty() ([]byte, error)
- func (p *SafeMap) MarshalYAML() (any, error)
- func (p *SafeMap) Merge(other map[string]any)
- func (p *SafeMap) MustGet(key string) any
- func (p *SafeMap) Set(key string, value any)
- func (p *SafeMap) UnmarshalJSON(data []byte) error
- func (p *SafeMap) UnmarshalYAML(value *yaml.Node) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Map ¶
Map is a map of string key and any value. It provides many useful methods to work with map[string]any.
func (Map) Get ¶
Get returns the value for the given key, ie: (value, true). If the value does not exist it returns (nil, false)
func (Map) GetDuration ¶
GetDuration returns the value associated with the key as a duration.
func (Map) GetInt32 ¶ added in v2.14.2
GetInt32 returns the value associated with the key as an int32.
func (Map) GetInt64 ¶ added in v2.14.2
GetInt64 returns the value associated with the key as an int64.
func (Map) GetOr ¶ added in v2.8.5
GetOr returns the value for the given key if it exists in the map, else it returns the default value.
func (Map) GetSlice ¶
GetSlice returns the value associated with the key as a slice. It returns nil if key does not present in Map or the value's type is not a slice.
func (Map) GetStringMap ¶
GetStringMap returns the value associated with the key as a map of (map[string]string).
func (Map) GetStrings ¶
GetStrings returns the value associated with the key as a slice of strings.
func (Map) GetUint32 ¶ added in v2.14.2
GetUint32 returns the value associated with the key as an uint32.
func (Map) GetUint64 ¶ added in v2.14.2
GetUint64 returns the value associated with the key as an uint64.
func (Map) Iterate ¶
Iterate iterates the map in unspecified order, the given function fn will be called for each key value pair. The iteration can be aborted by returning a non-zero value from fn.
func (Map) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface.
func (Map) MarshalJSONPretty ¶
MarshalJSONPretty returns its marshaled data as `[]byte` with indentation using two spaces.
func (Map) MarshalYAML ¶ added in v2.8.4
MarshalYAML implements the yaml.Marshaler interface.
func (*Map) Set ¶
Set is used to store a new key/value pair exclusively in the map. It also lazily initializes the map if it was not used previously.
func (*Map) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface.
func (*Map) UnmarshalYAML ¶ added in v2.8.4
UnmarshalYAML implements the yaml.Unmarshaler interface.
type SafeMap ¶
type SafeMap struct {
// contains filtered or unexported fields
}
SafeMap wraps a Map with a RWMutex to provide concurrent safety. It's safe for concurrent use by multiple goroutines.