github.com/cloudbase/juju-core@v0.0.0-20140504232958-a7271ac7912f/store/config.go (about) 1 // Copyright 2012, 2013 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package store 5 6 import ( 7 "fmt" 8 "io/ioutil" 9 "os" 10 11 "launchpad.net/goyaml" 12 ) 13 14 type Config struct { 15 MongoURL string `yaml:"mongo-url"` 16 APIAddr string `yaml:"api-addr"` 17 } 18 19 func ReadConfig(path string) (*Config, error) { 20 f, err := os.Open(path) 21 if err != nil { 22 return nil, fmt.Errorf("opening config file: %v", err) 23 } 24 defer f.Close() 25 data, err := ioutil.ReadAll(f) 26 if err != nil { 27 return nil, fmt.Errorf("reading config file: %v", err) 28 } 29 conf := new(Config) 30 err = goyaml.Unmarshal(data, conf) 31 if err != nil { 32 return nil, fmt.Errorf("processing config file: %v", err) 33 } 34 return conf, nil 35 }