maputil

package module
v0.0.0-...-b05a479 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2018 License: BSD-3-Clause Imports: 5 Imported by: 7

README

maputil: Map helpers

Map manipulation helpers for Go.

GoDoc

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidType represents an invalid configuration value type error.
	ErrInvalidType = errors.New("invalid value type")
	// ErrUnscannableValue represents an unscannable value error.
	ErrUnscannableValue = errors.New("unscannable value")
)

Functions

This section is empty.

Types

type Map

type Map map[string]interface{}

Map represents an instance of keys mapping.

All the function returning values associated with keys will return a fallback value if the key is not present in the map or if the value can't be converted to the requested type.

func (Map) Clone

func (m Map) Clone() Map

Clone returns a clone of the keys mapping instance.

func (Map) Flatten

func (m Map) Flatten(glue string) map[string]string

Flatten returns a "flattened" version of the map. * all nested elements are moved at the top level, with sub-level keys prefixed with the original key name using the glue string * any value whose type is different than maps or slice is returned as string representation (fmt "%v" verb) * slice elements are flattened, with their numeric index value as suffix * any pointer value is dereferenced

func (Map) GetBool

func (m Map) GetBool(key string, fallback bool) (bool, error)

GetBool returns the boolean value associated with a key.

func (Map) GetFloat

func (m Map) GetFloat(key string, fallback float64) (float64, error)

GetFloat returns the floating-point number value associated with a key.

func (Map) GetInt

func (m Map) GetInt(key string, fallback int) (int, error)

GetInt returns the integer value associated with a key.

func (Map) GetInt64

func (m Map) GetInt64(key string, fallback int64) (int64, error)

GetInt64 returns the 64-bit integer value associated with a key.

func (Map) GetInterface

func (m Map) GetInterface(key string, fallback interface{}) (interface{}, error)

GetInterface returns the interface value associated with a key.

func (Map) GetMap

func (m Map) GetMap(key string, fallback Map) (Map, error)

GetMap returns the map value associated with a key.

func (Map) GetString

func (m Map) GetString(key, fallback string) (string, error)

GetString returns the string value associated with a key.

func (Map) GetStringSlice

func (m Map) GetStringSlice(key string, fallback []string) ([]string, error)

GetStringSlice returns the string value associated with a key.

func (Map) Has

func (m Map) Has(key string) bool

Has returns true if key is present in the mapping, false otherwise.

func (*Map) Merge

func (m *Map) Merge(source Map, replace bool)

Merge merges the source map entries into the receiver map. If replace parameter is true, existing entries in the receiver map will be replaced with entries from the source map.

func (*Map) Scan

func (m *Map) Scan(v interface{}) error

Scan unmarshals the keys mapping retrieved from SQL drivers.

func (Map) Set

func (m Map) Set(k string, v interface{})

Set sets the mapping key k to the value v.

func (Map) Value

func (m Map) Value() (driver.Value, error)

Value marshals the keys mapping for compatibility with SQL drivers.

Jump to

Keyboard shortcuts

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