• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

.gitignoreH A D29-Nov-2015259 2418

LICENSEH A D29-Nov-20151.1 KiB2217

merger.goH A D29-Nov-20156.3 KiB223157

merger_test.goH A D29-Nov-20155.8 KiB299209

readme.mdH A D29-Nov-20152.1 KiB7855

readme.md

1Merger
2=====
3
4A go package to merge structs of the same type, filling zero values with non zero values from another.
5
6Merger is useful if you want to provide a default settings struct for something, or if you are working with database results and want to 'update' just some fields from a struct
7
8
9## Usage
10
11```
12Merge(&dst, src)
13````
14
15Being `&dst` a pointer to the destination struct and `src` the origin struct
16
17Example
18
19```
20package main
21
22import (
23	"fmt"
24	"github.com/worg/merger"
25)
26
27type Person struct {
28	ID      int
29	Name    string
30	Address string
31}
32
33var (
34	defaultPerson = Person{
35		Name:    `Homer`,
36		Address: `742 Evergreen Terrace`,
37	}
38)
39
40func main() {
41	p := Person{Name: `John`}
42
43	if err := merger.Merge(&p, defaultPerson); err != nil {
44		// handle err
45	}
46
47    fmt.Printf("p is: %+v", p)
48    // prints : p is {Id: 0, Name: John, Address: 742 Evergreen Terrace}
49}
50
51```
52
53
54## Notes
55
56Mergo won't merge non zero nor unexported fields , that is it will respect any value already present in dst.
57
58## License
59
60Copyright (c) 2014 Hiram Jerónimo Pérez worg{at}linuxmail[dot]org
61
62Permission is hereby granted, free of charge, to any person obtaining a copy
63of this software and associated documentation files (the "Software"), to deal
64in the Software without restriction, including without limitation the rights
65to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
66copies of the Software, and to permit persons to whom the Software is
67furnished to do so, subject to the following conditions:
68
69The above copyright notice and this permission notice shall be included in
70all copies or substantial portions of the Software.
71
72THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
73IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
74FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
75AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
76LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
77OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
78THE SOFTWARE.