ezmap

package
v2.14.7 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MarshalCSV added in v2.14.6

func MarshalCSV[T ~map[string]any](records []T) ([]byte, error)

MarshalCSV marshal map[string]any records to CSV encoding. It uses the std encoding/csv.Writer with its default settings for csv encoding. If length of records is zero, it returns (nil, nil).

Caller should guarantee that every record have same schema. The keys of the first item in records is used as the result CSV header, for the left items in records, if a key is missing, it is ignored, keys not present in the first item are simply ignored.

Types

type Map

type Map map[string]any

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

func NewMap

func NewMap() Map

NewMap returns a new initialized Map.

func UnmarshalCVS added in v2.14.6

func UnmarshalCVS(data []byte) ([]Map, error)

UnmarshalCVS parses CSV-encoded data to map[string]any records. It uses the std encoding/csv.Reader with its default settings for csv encoding. The first record parsed from the first row is treated as CSV header, and used as the result map keys.

func (Map) Get

func (p Map) Get(key string) (value any, 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) int

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

func (Map) GetInt32 added in v2.14.2

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 added in v2.14.2

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]any).

func (Map) GetOr added in v2.8.5

func (p Map) GetOr(key string, defaultVal any) (value any)

GetOr returns the value for the given key if it exists in the map, else it returns the default value.

func (Map) GetSlice

func (p Map) GetSlice(key string) any

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) GetUint added in v2.14.2

func (p Map) GetUint(key string) uint

GetUint returns the value associated with the key as an uint.

func (Map) GetUint32 added in v2.14.2

func (p Map) GetUint32(key string) uint32

GetUint32 returns the value associated with the key as an uint32.

func (Map) GetUint64 added in v2.14.2

func (p Map) GetUint64(key string) uint64

GetUint64 returns the value associated with the key as an uint64.

func (Map) Iterate

func (p Map) Iterate(fn func(k string, v any) 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) MarshalYAML added in v2.8.4

func (p Map) MarshalYAML() (any, error)

MarshalYAML implements the yaml.Marshaler interface.

func (*Map) Merge added in v2.14.1

func (p *Map) Merge(other map[string]any)

Merge merges key values from another map.

func (Map) MustGet

func (p Map) MustGet(key string) any

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

func (*Map) Set

func (p *Map) Set(key string, value any)

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.

func (*Map) UnmarshalYAML added in v2.8.4

func (p *Map) UnmarshalYAML(value *yaml.Node) error

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.

func NewSafeMap

func NewSafeMap() *SafeMap

NewSafeMap returns a new initialized SafeMap.

func (*SafeMap) Get added in v2.14.1

func (p *SafeMap) Get(key string) (value any, exists bool)

func (*SafeMap) GetBool added in v2.14.1

func (p *SafeMap) GetBool(key string) bool

func (*SafeMap) GetBytes added in v2.14.1

func (p *SafeMap) GetBytes(key string) []byte

func (*SafeMap) GetDuration added in v2.14.1

func (p *SafeMap) GetDuration(key string) time.Duration

func (*SafeMap) GetFloat added in v2.14.1

func (p *SafeMap) GetFloat(key string) float64

func (*SafeMap) GetInt added in v2.14.1

func (p *SafeMap) GetInt(key string) int

func (*SafeMap) GetInt32 added in v2.14.2

func (p *SafeMap) GetInt32(key string) int32

func (*SafeMap) GetInt32s added in v2.14.1

func (p *SafeMap) GetInt32s(key string) []int32

func (*SafeMap) GetInt64 added in v2.14.2

func (p *SafeMap) GetInt64(key string) int64

func (*SafeMap) GetInt64s added in v2.14.1

func (p *SafeMap) GetInt64s(key string) []int64

func (*SafeMap) GetMap added in v2.14.1

func (p *SafeMap) GetMap(key string) Map

func (*SafeMap) GetOr added in v2.14.1

func (p *SafeMap) GetOr(key string, defaultVal any) (value any)

func (*SafeMap) GetSlice added in v2.14.1

func (p *SafeMap) GetSlice(key string) any

func (*SafeMap) GetString added in v2.14.1

func (p *SafeMap) GetString(key string) string

func (*SafeMap) GetStringMap added in v2.14.1

func (p *SafeMap) GetStringMap(key string) map[string]string

func (*SafeMap) GetStrings added in v2.14.1

func (p *SafeMap) GetStrings(key string) []string

func (*SafeMap) GetTime added in v2.14.1

func (p *SafeMap) GetTime(key string) time.Time

func (*SafeMap) GetUint added in v2.14.2

func (p *SafeMap) GetUint(key string) uint

func (*SafeMap) GetUint32 added in v2.14.2

func (p *SafeMap) GetUint32(key string) uint32

func (*SafeMap) GetUint64 added in v2.14.2

func (p *SafeMap) GetUint64(key string) uint64

func (*SafeMap) Iterate added in v2.14.1

func (p *SafeMap) Iterate(fn func(k string, v any) int)

func (*SafeMap) MarshalJSON added in v2.14.1

func (p *SafeMap) MarshalJSON() ([]byte, error)

func (*SafeMap) MarshalJSONPretty added in v2.14.1

func (p *SafeMap) MarshalJSONPretty() ([]byte, error)

func (*SafeMap) MarshalYAML added in v2.14.1

func (p *SafeMap) MarshalYAML() (any, error)

func (*SafeMap) Merge added in v2.14.1

func (p *SafeMap) Merge(other map[string]any)

func (*SafeMap) MustGet added in v2.14.1

func (p *SafeMap) MustGet(key string) any

func (*SafeMap) Set added in v2.14.1

func (p *SafeMap) Set(key string, value any)

func (*SafeMap) UnmarshalJSON added in v2.14.1

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

func (*SafeMap) UnmarshalYAML added in v2.14.1

func (p *SafeMap) UnmarshalYAML(value *yaml.Node) error

Jump to

Keyboard shortcuts

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