Skip to content

Instantly share code, notes, and snippets.

@yujinqiu
Forked from bodokaiser/config.go
Last active August 29, 2015 14:19
Show Gist options
  • Save yujinqiu/130318bc093701e0e565 to your computer and use it in GitHub Desktop.
Save yujinqiu/130318bc093701e0e565 to your computer and use it in GitHub Desktop.
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