maps

package
v1.100.0 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

README

This module was initially created to vendor https://pkg.go.dev/github.com/hashicorp/terraform/flatmap which has been removed from the terraform project.

code has been updated and is also inspired from https://github.com/astaxie/flatmap

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Expand

func Expand(value map[string]string) (expandedMap any, err error)

func ExpandPrefixed

func ExpandPrefixed(m map[string]string, key string) (result any, err error)

ExpandPrefixed takes a maps and a prefix and expands that value into a more complex structure. This is the reverse of the Flatten operation.

Types

type Map

type Map map[string]string

Map is a wrapper around maps[string]string that provides some helpers above it that assume the maps is in the format that flatmap expects (the result of Flatten).

All modifying functions such as Delete are done in-place unless otherwise noted.

func Flatten

func Flatten(thing map[string]any) (result Map, err error)

Flatten takes a structure and turns into a flat maps[string]string.

Within the "thing" parameter, only primitive values are allowed. Structs are not supported. Therefore, it can only be slices, maps, primitives, and any combination of those together.

See the tests for examples of what inputs are turned into.

func (Map) AsMap

func (m Map) AsMap() map[string]string

func (Map) Contains

func (m Map) Contains(key string) bool

Contains returns true if the maps contains the given key.

func (Map) Delete

func (m Map) Delete(prefix string)

Delete deletes a key out of the maps with the given prefix.

func (Map) Keys

func (m Map) Keys() []string

Keys returns all the top-level keys in this maps

func (Map) Merge

func (m Map) Merge(m2 Map)

Merge merges the contents of the other Map into this one.

This merge is smarter than a simple maps iteration because it will fully replace arrays and other complex structures that are present in this maps with the other maps's. For example, if this maps has a 3 element "foo" list, and m2 has a 2 element "foo" list, then the result will be that m has a 2 element "foo" list.

Jump to

Keyboard shortcuts

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