gemap

package
v0.17.3 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IntKeys

func IntKeys(m interface{}) (keys []int64)

IntKeys returns a int64 slice containing all the keys present in the map, in unspecified order. It panics if m's kind is not reflect.Map or the key's type is not integer. It returns an empty slice if m is a nil map.

func IntValues

func IntValues(m interface{}) (values []int64)

IntValues returns a int64 slice containing all the values present in the map, in unspecified order. It panics if m's kind is not reflect.Map or the value's type is not integer. It returns an empty slice if m is a nil map.

func MapKeys

func MapKeys(m interface{}) (keys interface{})

MapKeys returns a slice containing all the keys present in the map, in unspecified order. It panics if m's kind is not reflect.Map. It returns an emtpy slice if m is a nil map.

func MapValues

func MapValues(m interface{}) (values interface{})

MapValues returns a slice containing all the values present in the map, in unspecified order. It panics if m's kind is not reflect.Map. It returns an empty slice if m is a nil map.

func MergeMaps

func MergeMaps(maps ...interface{}) interface{}

MergeMaps returns a new map containing all key values present in maps. It panics if given zero param. It panics if given param which is not a map, or different map types. It returns an empty map if all params are nil or empty.

func MergeMapsTo

func MergeMapsTo(dst interface{}, others ...interface{}) interface{}

MergeMapsTo adds key values present in others to the dst map. It panics if dst is nil or not a map, or any param in others is not a map, or they are different map types. If dst is a nil map, it creates a new map and returns it.

func StringKeys

func StringKeys(m interface{}) (keys []string)

StringKeys returns a string slice containing all the keys present in the map, in unspecified order. It panics if m's kind is not reflect.Map or the key's kind is not string. It returns an empty slice if m is a nil map.

func StringValues

func StringValues(m interface{}) (values []string)

StringValues returns a string slice containing all the values present in the map, in unspecified order. It panics if m's kind is not reflect.Map or the value's kind is not string. It returns an empty slice if m is a nil map.

Types

type Map

type Map map[string]interface{}

Map is a map of string key and interface{} value. It provides many useful methods to manipulate map[string]interface{}.

func NewMap

func NewMap() Map

NewMap returns a new initialized Map instance.

func (Map) Get

func (p Map) Get(key string) (value interface{}, exists bool)

Get returns the value for the given key, ie: (value, true). If the value does not exist it returns (nil, false)

func (Map) GetBool

func (p Map) GetBool(key string) bool

GetBool returns the value associated with the key as a boolean value.

func (Map) GetBytes

func (p Map) GetBytes(key string) []byte

GetBytes returns the value associated with the key as bytes.

func (Map) GetDuration

func (p Map) GetDuration(key string) time.Duration

GetDuration returns the value associated with the key as a duration.

func (Map) GetFloat64

func (p Map) GetFloat64(key string) float64

GetFloat64 returns the value associated with the key as a float64.

func (Map) GetInt

func (p Map) GetInt(key string) int

GetInt returns the value associated with the key as an integer.

func (Map) GetInt32

func (p Map) GetInt32(key string) int32

GetInt32 returns the value associated with the key as an int32.

func (Map) GetInt32s

func (p Map) GetInt32s(key string) []int32

GetInt32s returns the value associated with the key as a slice of int32.

func (Map) GetInt64

func (p Map) GetInt64(key string) int64

GetInt64 returns the value associated with the key as an int64.

func (Map) GetInt64s

func (p Map) GetInt64s(key string) []int64

GetInt64s returns the value associated with the key as a slice of int64.

func (Map) GetMap

func (p Map) GetMap(key string) Map

GetMap returns the value associated with the key as a Map (map[string]interface{}).

func (Map) GetSlice

func (p Map) GetSlice(key string) []interface{}

GetSlice returns the value associated with the key as []interface{}. It returns nil if key does not present in Map or the value's type is not []interface{}.

func (Map) GetString

func (p Map) GetString(key string) string

GetString returns the value associated with the key as a string.

func (Map) GetStrings

func (p Map) GetStrings(key string) []string

GetStrings returns the value associated with the key as a slice of strings.

func (Map) GetStrstrMap

func (p Map) GetStrstrMap(key string) map[string]string

GetStrstrMap returns the value associated with the key as a map of (map[string]string).

func (Map) GetTime

func (p Map) GetTime(key string) time.Time

GetTime returns the value associated with the key as time.

func (Map) Iterate

func (p Map) Iterate(fn func(k string, v interface{}) int)

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) MustGet

func (p Map) MustGet(key string) interface{}

MustGet returns the value for the given key if it exists, otherwise it panics.

func (*Map) Set

func (p *Map) Set(key string, value interface{})

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.

type SafeMap

type SafeMap struct {
	sync.RWMutex
	Map Map
}

SafeMap wraps a RWMutex with Map to provide concurrent safety.

func NewSafeMap

func NewSafeMap() *SafeMap

NewSafeMap returns a new initialized SafeMap instance.

Jump to

Keyboard shortcuts

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