maps

package
v1.2.7 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2021 License: GPL-3.0 Imports: 4 Imported by: 1

Documentation

Overview

Map functions such as deep copying and equality testing.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func CopyMap

func CopyMap(m map[string]interface{}) map[string]interface{}

Clones a map deeply using recursion.

Example

Deep copying a map using recursion via CopyMap.

CopyMap was designed for use with deserialised JSONs hence the map[string]interface{} signature.

original := map[string]interface{}{
	"hello": "world",
	"age":   20,
	"bald":  false,
	"friends": []interface{}{
		"Bob",
		"Jane",
		"John",
		"Mark",
		map[string]interface{}{
			"name": "Gregor",
			"age":  31,
			"friends": []interface{}{
				"Bill",
				"Bob",
				"Sarah",
			},
		},
	},
}
// Clone the above map.
clone := CopyMap(original)

fmt.Println("Original:", original)
fmt.Println("Clone:", clone)
Output:

Original: map[age:20 bald:false friends:[Bob Jane John Mark map[age:31 friends:[Bill Bob Sarah] name:Gregor]] hello:world]
Clone: map[age:20 bald:false friends:[Bob Jane John Mark map[age:31 friends:[Bill Bob Sarah] name:Gregor]] hello:world]

func JsonMapEqualTest

func JsonMapEqualTest(t *testing.T, actual, expected interface{}, forString string)

Used in tests to check equality between two interface{}s.

This takes into account orderings of slices.

Types

This section is empty.

Jump to

Keyboard shortcuts

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