A helper to merge structs 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.
It is quick hack to scratch my own itch around how to handle configuration default values. It works fine but it needs a lot more of testing and real world usage.
go get github.com/imdario/mergo
// use in your .go code
import (
"github.com/imdario/mergo"
)
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. In maps Mergo won't merge equal keys values, because they are not addressable under reflection.
if err := mergo.Merge(&dst, src); err != nil {
// ...
}
More information and examples in godoc documentation.
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
Written by Dario Castañé.
BSD 3-Clause license, as Go language.