Documentation ¶
Overview ¶
Package maps provides reusable functions for manipulating nested map[string]interface{} maps are common unmarshal products from various serializers such as json, yaml etc.
Index ¶
- func Copy(mp map[string]interface{}) map[string]interface{}
- func Flatten(m map[string]interface{}, keys []string, delim string) (map[string]interface{}, map[string][]string)
- func Int64SliceToLookupMap(s []int64) map[int64]bool
- func IntfaceKeysToStrings(mp map[string]interface{})
- func Merge(a, b map[string]interface{})
- func Search(mp map[string]interface{}, path []string) interface{}
- func StringSliceToLookupMap(s []string) map[string]bool
- func Unflatten(m map[string]interface{}, delim string) map[string]interface{}
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Copy ¶
Copy returns a copy of a conf map by doing a JSON marshal+unmarshal pass. Inefficient, but creates a true deep copy. There is a side effect, that is, all numeric types change to float64.
It's important to note that all nested maps should be map[string]interface{} and not map[interface{}]interface{}. Use IntfaceKeysToStrings() to convert if necessary.
func Flatten ¶
func Flatten(m map[string]interface{}, keys []string, delim string) (map[string]interface{}, map[string][]string)
Flatten takes a map[string]interface{} and traverses it and flattens nested children into keys delimited by delim.
It's important to note that all nested maps should be map[string]interface{} and not map[interface{}]interface{}. Use IntfaceKeysToStrings() to convert if necessary.
eg: `{ "parent": { "child": 123 }}` becomes `{ "parent.child": 123 }` In addition, it keeps track of and returns a map of the delimited keypaths with a slice of key parts, for eg: { "parent.child": ["parent", "child"] }. This parts list is used to remember the key path's original structure to unflatten later.
func Int64SliceToLookupMap ¶
Int64SliceToLookupMap takes a slice of int64s and returns a lookup map with the slice values as keys with true values.
func IntfaceKeysToStrings ¶
func IntfaceKeysToStrings(mp map[string]interface{})
IntfaceKeysToStrings recursively converts map[interface{}]interface{} to map[string]interface{}. Some parses such as YAML unmarshal return this.
func Merge ¶
func Merge(a, b map[string]interface{})
Merge recursively merges map a into b (left to right), mutating and expanding map b. Note that there's no copying involved, so map b will retain references to map a.
It's important to note that all nested maps should be map[string]interface{} and not map[interface{}]interface{}. Use IntfaceKeysToStrings() to convert if necessary.
func Search ¶
Search recursively searches a map for a given path. The path is the key map slice, for eg:, parent.child.key -> [parent child key].
It's important to note that all nested maps should be map[string]interface{} and not map[interface{}]interface{}. Use IntfaceKeysToStrings() to convert if necessary.
func StringSliceToLookupMap ¶
StringSliceToLookupMap takes a slice of strings and returns a lookup map with the slice values as keys with true values.
func Unflatten ¶
Unflatten takes a flattened key:value map (non-nested with delimited keys) and returns a nested map where the keys are split into hierarchies by the given delimiter. For instance, `parent.child.key: 1` to `{parent: {child: {key: 1}}}`
It's important to note that all nested maps should be map[string]interface{} and not map[interface{}]interface{}. Use IntfaceKeysToStrings() to convert if necessary.
Types ¶
This section is empty.