Documentation ¶
Index ¶
- Variables
- func Clear[K comparable, V any](mm ...map[K]V)
- func DNSToMap(msg *dns.Msg, format string) (m map[string]interface{})
- func Difference[K comparable, V any](m map[K]V, keys ...K) map[K]V
- func Flatten(m map[string]any, separator string) map[string]any
- func GetKeys[K comparable, V any](maps ...map[K]V) []K
- func GetValues[K comparable, V any](maps ...map[K]V) []V
- func HTTPRequestToMap(req *http.Request) (map[string]interface{}, error)
- func HTTPResponseToMap(resp *http.Response) (map[string]interface{}, error)
- func HTTPToMap(resp *http.Response, body, headers string, duration time.Duration, ...) (m map[string]interface{})
- func IsEmpty[K comparable, V any](m map[K]V) bool
- func Merge[K comparable, V any](maps ...map[K]V) (result map[K]V)
- func SliceToMap[T comparable](s []T, dflt T) map[T]T
- func Walk(m map[string]any, callback func(k string, v any))
- type Map
- type SyncLockMap
Constants ¶
This section is empty.
Variables ¶
var (
ErrReadOnly = errors.New("read only mode")
)
Functions ¶
func Clear ¶ added in v0.0.3
func Clear[K comparable, V any](mm ...map[K]V)
Clear the map passed as parameter
func Difference ¶
func Difference[K comparable, V any](m map[K]V, keys ...K) map[K]V
Difference returns the inputted map without the keys specified as input.
func Flatten ¶
Flatten takes a map and returns a new one where nested maps are replaced by dot-delimited keys.
func GetKeys ¶
func GetKeys[K comparable, V any](maps ...map[K]V) []K
GetKeys returns the map's keys.
func GetValues ¶
func GetValues[K comparable, V any](maps ...map[K]V) []V
GetValues returns the map's values.
func HTTPRequestToMap ¶ added in v0.0.3
HTTPRequestToMap Converts HTTP Request to Matcher Map
func HTTPResponseToMap ¶
HTTPResponseToMap Converts HTTP Response to Matcher Map
func HTTPToMap ¶
func HTTPToMap(resp *http.Response, body, headers string, duration time.Duration, format string) (m map[string]interface{})
HTTPToMap Converts HTTP to Matcher Map
func IsEmpty ¶ added in v0.0.3
func IsEmpty[K comparable, V any](m map[K]V) bool
IsEmpty checks if a map is empty.
func Merge ¶ added in v0.0.3
func Merge[K comparable, V any](maps ...map[K]V) (result map[K]V)
Merge merges the inputted maps into a new one. Be aware: In case of duplicated keys in multiple maps, the one ending in the result is unknown a priori.
func SliceToMap ¶ added in v0.0.3
func SliceToMap[T comparable](s []T, dflt T) map[T]T
SliceToMap returns a map having as keys the elements in even positions and as values the elements in odd positions. If the number of elements is odd the default value applies.
Types ¶
type Map ¶ added in v0.0.8
type Map[K comparable, V any] map[K]V
Map wraps a generic map type
func (Map[K, V]) GetKeys ¶ added in v0.0.8
func (m Map[K, V]) GetKeys(keys ...K) []V
GetKeys from the map as a slice
func (Map[K, V]) GetOrDefault ¶ added in v0.0.8
func (m Map[K, V]) GetOrDefault(key K, defaultValue V) V
GetOrDefault the provided key or default to the provided value
type SyncLockMap ¶ added in v0.0.8
type SyncLockMap[K comparable, V any] struct { ReadOnly atomic.Bool Map Map[K, V] // contains filtered or unexported fields }
SyncLock adds sync and lock capabilities to generic map
func (*SyncLockMap[K, V]) Get ¶ added in v0.0.8
func (s *SyncLockMap[K, V]) Get(k K) (V, bool)
Get an item with syncronous access
func (*SyncLockMap[K, V]) Iterate ¶ added in v0.0.8
func (s *SyncLockMap[K, V]) Iterate(f func(k K, v V) error) error
Iterate with a callback function synchronously
func (*SyncLockMap[K, V]) Lock ¶ added in v0.0.8
func (s *SyncLockMap[K, V]) Lock()
Lock the current map to read-only mode
func (*SyncLockMap[K, V]) Set ¶ added in v0.0.8
func (s *SyncLockMap[K, V]) Set(k K, v V) error
Set an item with syncronous access
func (*SyncLockMap[K, V]) Unlock ¶ added in v0.0.8
func (s *SyncLockMap[K, V]) Unlock()
Unlock the current map