mergemap

package module
Version: v0.0.0-...-e21c03b Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2013 License: BSD-2-Clause Imports: 1 Imported by: 49

README

mergemap

mergemap is a Go library to recursively merge JSON maps.

Build Status

Behavior

mergemap performs a simple merge of the src map into the dst map. That is, it takes the src value when there is a key conflict.

The only special behavior is when the conflicting key represents a map in both src and dst. Then, mergemap recursively descends into both maps, repeating the same logic. The max recursion depth is set by mergemap.MaxDepth.

Usage

var m1, m2 map[string]interface{}
json.Unmarshal(buf1, &m1)
json.Unmarshal(buf2, &m2)

merged := mergemap.Merge(m1, m2)

See the test file for some pretty straightforward examples.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	MaxDepth = 32
)

Functions

func Merge

func Merge(dst, src map[string]interface{}) map[string]interface{}

Merge recursively merges the src and dst maps. Key conflicts are resolved by preferring src, or recursively descending, if both src and dst are maps.

Types

This section is empty.

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL