go-merge is a golang library for recursively merging data. It will merge and overwrite maps, structs, and other basic golang types as long as the base data and the override data are of a similar structure.
To use this package first you must install it:
go get github.com/divideandconquer/go-merge/merge
Then you can import it in your code and use it as follows:
package main
import (
"log"
"github.com/divideandconquer/go-merge/merge"
)
func main() {
baseData := make(map[string]string)
baseData["test"] = "foo"
baseData["test2"] = "bar"
overrideData := make(map[string]string)
overrideData["test2"] = "override"
result := merge.Merge(baseData, overrideData)
log.Printf("%#v", result) // prints: map[string]string{"test":"foo", "test2":"override"}
}
For more examples of usage check the unit tests.
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Add tests for your changes
- Test your changes (
go test merge/*.go
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
This library is licensed using the Apache-2.0 License:
Copyright (c) 2015, Kyle Boorky