2013-05-10 20:22:58 +00:00
|
|
|
package config
|
2013-02-09 04:29:43 +00:00
|
|
|
|
|
|
|
import (
|
2013-03-27 20:30:24 +00:00
|
|
|
"io/ioutil"
|
|
|
|
"launchpad.net/goyaml"
|
2013-02-09 04:29:43 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type Config map[string]interface{}
|
|
|
|
|
2013-05-10 20:22:58 +00:00
|
|
|
// Of the configurations, provided option, return the value as a bool
|
2013-02-09 04:29:43 +00:00
|
|
|
func (c *Config) GetBool(option string) (value bool) {
|
2013-03-27 20:30:24 +00:00
|
|
|
conf := Config{}
|
|
|
|
conf = *c
|
|
|
|
switch conf[option] {
|
|
|
|
default:
|
|
|
|
value = false
|
|
|
|
case "yes", "on", "true":
|
|
|
|
value = true
|
|
|
|
}
|
|
|
|
return
|
2013-02-09 04:29:43 +00:00
|
|
|
}
|
|
|
|
|
2013-05-10 20:22:58 +00:00
|
|
|
// Of the configurations, provided option, return the value as a string
|
2013-02-09 04:29:43 +00:00
|
|
|
func (c *Config) GetString(option string) (value string) {
|
2013-03-27 20:30:24 +00:00
|
|
|
conf := Config{}
|
|
|
|
conf = *c
|
|
|
|
value, _ = conf[option].(string)
|
|
|
|
return
|
2013-02-09 04:29:43 +00:00
|
|
|
}
|
|
|
|
|
2013-05-10 20:22:58 +00:00
|
|
|
// Given a filename to a YAML file, unmarshal it, and return a Config
|
2013-02-09 04:29:43 +00:00
|
|
|
func ReadConfigFile(filename string) (config Config, err error) {
|
2013-03-27 20:30:24 +00:00
|
|
|
bytes, err := ioutil.ReadFile(filename)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
2013-02-09 04:29:43 +00:00
|
|
|
|
2013-03-27 20:30:24 +00:00
|
|
|
err = goyaml.Unmarshal(bytes, &config)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
2013-02-09 04:29:43 +00:00
|
|
|
|
2013-03-27 20:30:24 +00:00
|
|
|
return config, nil
|
2013-02-09 04:29:43 +00:00
|
|
|
}
|
|
|
|
|
2013-05-10 20:22:58 +00:00
|
|
|
/*
|
2013-02-09 04:29:43 +00:00
|
|
|
func WriteConfigFile(filename string, data []byte) (err error) {
|
2013-03-27 20:30:24 +00:00
|
|
|
return
|
2013-02-09 04:29:43 +00:00
|
|
|
}
|
2013-05-10 20:22:58 +00:00
|
|
|
*/
|