ezmap

package
v2.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetTyped

func GetTyped[T any](m map[string]any, key string) T

GetTyped returns the value associated with key as type T, if exists.

Types

type Map

type Map map[string]interface{}

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

func NewMap

func NewMap() Map

NewMap returns a new initialized Map.

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

func (p Map) GetFloat(key string) float64

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

func (Map) GetInt

func (p Map) GetInt(key string) int64

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

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) 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 a slice. It returns nil if key does not present in Map or the value's type is not a slice.

func (Map) GetString

func (p Map) GetString(key string) string

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

func (Map) GetStringMap

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

GetStringMap returns the value associated with the key as a map of (map[string]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) 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) MarshalJSON

func (p Map) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (Map) MarshalJSONPretty

func (p Map) MarshalJSONPretty() ([]byte, error)

MarshalJSONPretty returns its marshaled data as `[]byte` with indentation using two spaces.

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.

func (*Map) UnmarshalJSON

func (p *Map) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

type SafeMap

type SafeMap struct {
	sync.RWMutex
	Map
}

SafeMap wraps a Map with a RWMutex to provide concurrent safety.

func NewSafeMap

func NewSafeMap() *SafeMap

NewSafeMap returns a new initialized SafeMap.

Jump to

Keyboard shortcuts

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