mapsutil

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2023 License: MIT Imports: 11 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Clear

func Clear[K comparable, V any](mm ...map[K]V)

Clear the map passed as parameter

func DNSToMap

func DNSToMap(msg *dns.Msg, format string) (m map[string]interface{})

DNSToMap Converts DNS to Matcher Map

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

func Flatten(m map[string]any, separator string) map[string]any

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 GetSortedKeys

func GetSortedKeys[K constraints.Ordered, V any](maps ...map[K]V) []K

GetSortedKeys returns the map's keys sorted.

func GetValues

func GetValues[K comparable, V any](maps ...map[K]V) []V

GetValues returns the map's values.

func HTTPRequestToMap

func HTTPRequestToMap(req *http.Request) (map[string]interface{}, error)

HTTPRequestToMap Converts HTTP Request to Matcher Map

func HTTPResponseToMap

func HTTPResponseToMap(resp *http.Response) (map[string]interface{}, error)

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

func IsEmpty[K comparable, V any](m map[K]V) bool

IsEmpty checks if a map is empty.

func Merge

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

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.

func Walk

func Walk(m map[string]any, callback func(k string, v any))

Walk a map and visit all the edge key:value pairs

Types

type Map

type Map[K, V comparable] map[K]V

Map wraps a generic map type

func (Map[K, V]) Clone

func (m Map[K, V]) Clone() Map[K, V]

Clone the current map

func (Map[K, V]) Get

func (m Map[K, V]) Get(key K) (V, bool)

Get returns the value for the provided key

func (Map[K, V]) GetKeyWithValue

func (m Map[K, V]) GetKeyWithValue(value V) (K, bool)

GetKeyWithValue returns the first key having value

func (Map[K, V]) GetKeys

func (m Map[K, V]) GetKeys(keys ...K) []V

GetKeys from the map as a slice

func (Map[K, V]) GetOrDefault

func (m Map[K, V]) GetOrDefault(key K, defaultValue V) V

GetOrDefault the provided key or default to the provided value

func (Map[K, V]) Has

func (m Map[K, V]) Has(key K) bool

Has checks if the current map has the provided key

func (Map[K, V]) IsEmpty

func (m Map[K, V]) IsEmpty() bool

IsEmpty checks if the current map is empty

func (Map[K, V]) Merge

func (m Map[K, V]) Merge(n map[K]V)

Merge the current map with the provided one

func (Map[K, V]) Set

func (m Map[K, V]) Set(key K, value V)

Set the provided key with the provided value

Jump to

Keyboard shortcuts

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