Skip to content

Instantly share code, notes, and snippets.

@collinvandyck
Created September 12, 2012 18:48
Show Gist options
  • Select an option

  • Save collinvandyck/3709014 to your computer and use it in GitHub Desktop.

Select an option

Save collinvandyck/3709014 to your computer and use it in GitHub Desktop.
type Config struct {
Db struct {
Name string
User string
Password string
}
}
func ReadConfig() Config {
if len(os.Args) != 2 {
log.Fatal("You must supply a configuration filename")
}
filename := os.Args[1]
bytes, err := ioutil.ReadFile(filename)
if err != nil {
panic(err)
}
var c Config
err = json.Unmarshal(bytes, &c)
if err != nil {
panic(err)
}
return c
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment