cri-o/vendor/github.com/imdario/mergo
Jonathan Yu 6c9628cdb1
Build and install from GOPATH
* Rename 'vendor/src' -> 'vendor'
  * Ignore vendor/ instead of vendor/src/ for lint
* Rename 'cmd/client' -> 'cmd/ocic' to make it 'go install'able
* Rename 'cmd/server' -> 'cmd/ocid' to make it 'go install'able
* Update Makefile to build and install from GOPATH
* Update tests to locate ocid/ocic in GOPATH/bin
* Search for binaries in GOPATH/bin instead of PATH
* Install tools using `go get -u`, so they are updated on each run

Signed-off-by: Jonathan Yu <jawnsy@redhat.com>
2017-01-17 12:09:09 -08:00
..
.travis.yml Build and install from GOPATH 2017-01-17 12:09:09 -08:00
doc.go Build and install from GOPATH 2017-01-17 12:09:09 -08:00
LICENSE Build and install from GOPATH 2017-01-17 12:09:09 -08:00
map.go Build and install from GOPATH 2017-01-17 12:09:09 -08:00
merge.go Build and install from GOPATH 2017-01-17 12:09:09 -08:00
mergo.go Build and install from GOPATH 2017-01-17 12:09:09 -08:00
README.md Build and install from GOPATH 2017-01-17 12:09:09 -08:00

Mergo

A helper to merge structs and maps in Golang. Useful for configuration default values, avoiding messy if-statements.

Also a lovely comune (municipality) in the Province of Ancona in the Italian region Marche.

Mergo dall'alto

Status

It is ready for production use. It works fine although it may use more of testing. Here some projects in the wild using Mergo:

Build Status GoDoc

Installation

go get github.com/imdario/mergo

// use in your .go code
import (
    "github.com/imdario/mergo"
)

Usage

You can only merge same-type structs with exported fields initialized as zero value of their type and same-types maps. Mergo won't merge unexported (private) fields but will do recursively any exported one. Also maps will be merged recursively except for structs inside maps (because they are not addressable using Go reflection).

if err := mergo.Merge(&dst, src); err != nil {
    // ...
}

Additionally, you can map a map[string]interface{} to a struct (and otherwise, from struct to map), following the same restrictions as in Merge(). Keys are capitalized to find each corresponding exported field.

if err := mergo.Map(&dst, srcMap); err != nil {
    // ...
}

Warning: if you map a struct to map, it won't do it recursively. Don't expect Mergo to map struct members of your struct as map[string]interface{}. They will be just assigned as values.

More information and examples in godoc documentation.

Note: if test are failing due missing package, please execute:

go get gopkg.in/yaml.v1

Contact me

If I can help you, you have an idea or you are using Mergo in your projects, don't hesitate to drop me a line (or a pull request): @im_dario

About

Written by Dario Castañé.

License

BSD 3-Clause license, as Go language.