Skip to content

Instantly share code, notes, and snippets.

@bodokaiser
Created June 26, 2014 08:16
Show Gist options
  • Save bodokaiser/281851282e9519c6b9bc to your computer and use it in GitHub Desktop.
Save bodokaiser/281851282e9519c6b9bc to your computer and use it in GitHub Desktop.
Simple example how to merge JSON files.
package main
import (
"log"
"fmt"
"encoding/json"
)
var conf1 = `
{
"name": "my-app"
}
`
var conf2 = `
{
"port": ":3000"
}
`
type Config struct {
Name string
Port string
}
func main() {
c := &Config{}
if err := json.Unmarshal([]byte(conf1), c); err != nil {
log.Fatal(err)
}
if err := json.Unmarshal([]byte(conf2), c); err != nil {
log.Fatal(err)
}
fmt.Printf("%#v", c)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment