blob: 6e9aa7baf35401f530ba93bdaa8f90b1756ab4c2 [file] [log] [blame]
Kent Hagermane566c2e2019-06-03 17:56:42 -04001// Copyright 2013 Dario Castañé. All rights reserved.
2// Copyright 2009 The Go Authors. All rights reserved.
3// Use of this source code is governed by a BSD-style
4// license that can be found in the LICENSE file.
5
6/*
7Package mergo merges same-type structs and maps by setting default values in zero-value fields.
8
9Mergo won't merge unexported (private) fields but will do recursively any exported one. It also won't merge structs inside maps (because they are not addressable using Go reflection).
10
11Usage
12
13From my own work-in-progress project:
14
15 type networkConfig struct {
16 Protocol string
17 Address string
18 ServerType string `json: "server_type"`
19 Port uint16
20 }
21
22 type FssnConfig struct {
23 Network networkConfig
24 }
25
26 var fssnDefault = FssnConfig {
27 networkConfig {
28 "tcp",
29 "127.0.0.1",
30 "http",
31 31560,
32 },
33 }
34
35 // Inside a function [...]
36
37 if err := mergo.Merge(&config, fssnDefault); err != nil {
38 log.Fatal(err)
39 }
40
41 // More code [...]
42
43*/
44package mergo