Tizen_4.0 base
[platform/upstream/docker-engine.git] / vendor / github.com / imdario / mergo / README.md
1 # Mergo
2
3 A helper to merge structs and maps in Golang. Useful for configuration default values, avoiding messy if-statements.
4
5 Also a lovely [comune](http://en.wikipedia.org/wiki/Mergo) (municipality) in the Province of Ancona in the Italian region Marche.
6
7 ![Mergo dall'alto](http://www.comune.mergo.an.it/Siti/Mergo/Immagini/Foto/mergo_dall_alto.jpg)
8
9 ## Status
10
11 It is ready for production use. It works fine after extensive use in the wild.
12
13 [![Build Status][1]][2]
14 [![GoDoc](https://godoc.org/github.com/imdario/mergo?status.svg)](https://godoc.org/github.com/imdario/mergo)
15
16 [1]: https://travis-ci.org/imdario/mergo.png
17 [2]: https://travis-ci.org/imdario/mergo
18
19 ### Important note
20
21 Mergo is intended to assign **only** zero value fields on destination with source value. Since April 6th it works like this. Before it didn't work properly, causing some random overwrites. After some issues and PRs I found it didn't merge as I designed it. Thanks to [imdario/mergo#8](https://github.com/imdario/mergo/pull/8) overwriting functions were added and the wrong behavior was clearly detected.
22
23 If you were using Mergo **before** April 6th 2015, please check your project works as intended after updating your local copy with ```go get -u github.com/imdario/mergo```. I apologize for any issue caused by its previous behavior and any future bug that Mergo could cause (I hope it won't!) in existing projects after the change (release 0.2.0).
24
25 ### Mergo in the wild
26
27 - [imdario/zas](https://github.com/imdario/zas)
28 - [GoogleCloudPlatform/kubernetes](https://github.com/GoogleCloudPlatform/kubernetes)
29 - [soniah/dnsmadeeasy](https://github.com/soniah/dnsmadeeasy)
30 - [EagerIO/Stout](https://github.com/EagerIO/Stout)
31 - [lynndylanhurley/defsynth-api](https://github.com/lynndylanhurley/defsynth-api)
32 - [russross/canvasassignments](https://github.com/russross/canvasassignments)
33 - [rdegges/cryptly-api](https://github.com/rdegges/cryptly-api)
34 - [casualjim/exeggutor](https://github.com/casualjim/exeggutor)
35 - [divshot/gitling](https://github.com/divshot/gitling)
36 - [RWJMurphy/gorl](https://github.com/RWJMurphy/gorl)
37 - [andrerocker/deploy42](https://github.com/andrerocker/deploy42)
38 - [elwinar/rambler](https://github.com/elwinar/rambler)
39 - [tmaiaroto/gopartman](https://github.com/tmaiaroto/gopartman)
40 - [jfbus/impressionist](https://github.com/jfbus/impressionist)
41 - [Jmeyering/zealot](https://github.com/Jmeyering/zealot)
42 - [godep-migrator/rigger-host](https://github.com/godep-migrator/rigger-host)
43 - [Dronevery/MultiwaySwitch-Go](https://github.com/Dronevery/MultiwaySwitch-Go)
44 - [thoas/picfit](https://github.com/thoas/picfit)
45 - [mantasmatelis/whooplist-server](https://github.com/mantasmatelis/whooplist-server)
46 - [jnuthong/item_search](https://github.com/jnuthong/item_search)
47
48 ## Installation
49
50     go get github.com/imdario/mergo
51
52     // use in your .go code
53     import (
54         "github.com/imdario/mergo"
55     )
56
57 ## Usage
58
59 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).
60
61     if err := mergo.Merge(&dst, src); err != nil {
62         // ...
63     }
64
65 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.
66
67     if err := mergo.Map(&dst, srcMap); err != nil {
68         // ...
69     }
70
71 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.
72
73 More information and examples in [godoc documentation](http://godoc.org/github.com/imdario/mergo).
74
75 ### Nice example
76
77 ```go
78 package main
79
80 import (
81         "fmt"
82         "github.com/imdario/mergo"
83 )
84
85 type Foo struct {
86         A string
87         B int64
88 }
89
90 func main() {
91         src := Foo{
92                 A: "one",
93         }
94
95         dest := Foo{
96                 A: "two",
97                 B: 2,
98         }
99
100         mergo.Merge(&dest, src)
101
102         fmt.Println(dest)
103         // Will print
104         // {two 2}
105 }
106 ```
107
108 Note: if test are failing due missing package, please execute:
109
110     go get gopkg.in/yaml.v1
111
112 ## Contact me
113
114 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](https://twitter.com/im_dario)
115
116 ## About
117
118 Written by [Dario Castañé](http://dario.im).
119
120 ## License
121
122 [BSD 3-Clause](http://opensource.org/licenses/BSD-3-Clause) license, as [Go language](http://golang.org/LICENSE).