merger

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: May 15, 2018 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package merger recursively merge two data structures into new one. Only maps and structures are recursively merging. Values of other kinds (e.g. slices) do not merging. Non-zero value from the right side has precedence.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Merge

func Merge(a, b interface{}) interface{}

Merge method performs recursive merge of two data structures into new one.

Example
package main

import (
	"fmt"

	"github.com/iph0/conf/merger"
)

func main() {
	type Connector struct {
		Host     string
		Port     int
		Username string
		Password string
		DBName   string
	}

	defaultConnrs := map[string]Connector{
		"stat": Connector{
			Port:     1234,
			Username: "stat_writer",
			DBName:   "stat",
		},

		"messages": Connector{
			Host:     "messages.mydb.com",
			Port:     5678,
			Username: "moo",
			Password: "moo_pass",
			DBName:   "messages",
		},
	}

	connrs := map[string]Connector{
		"stat": Connector{
			Host:     "stat.mydb.com",
			Username: "foo",
			Password: "foo_pass",
		},

		"metrics": Connector{
			Host:     "metrics.mydb.com",
			Port:     4321,
			Username: "bar",
			Password: "bar_pass",
			DBName:   "metrics",
		},
	}

	connrs = merger.Merge(defaultConnrs, connrs).(map[string]Connector)

	for name, connr := range connrs {
		fmt.Printf("%s: %v\n", name, connr)
	}

}
Output:

stat: {stat.mydb.com 1234 foo foo_pass stat}
messages: {messages.mydb.com 5678 moo moo_pass messages}
metrics: {metrics.mydb.com 4321 bar bar_pass metrics}

Types

This section is empty.

Jump to

Keyboard shortcuts

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