doc.go 978 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // 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. Package mergo merges same-type structs and maps by setting default values in zero-value fields.
  7. Mergo 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).
  8. Usage
  9. From my own work-in-progress project:
  10. type networkConfig struct {
  11. Protocol string
  12. Address string
  13. ServerType string `json: "server_type"`
  14. Port uint16
  15. }
  16. type FssnConfig struct {
  17. Network networkConfig
  18. }
  19. var fssnDefault = FssnConfig {
  20. networkConfig {
  21. "tcp",
  22. "127.0.0.1",
  23. "http",
  24. 31560,
  25. },
  26. }
  27. // Inside a function [...]
  28. if err := mergo.Merge(&config, fssnDefault); err != nil {
  29. log.Fatal(err)
  30. }
  31. // More code [...]
  32. */
  33. package mergo