1
0
Fork 0
mirror of https://github.com/vbatts/imgsrv.git synced 2024-12-26 15:56:31 +00:00
imgsrv/config.go

46 lines
726 B
Go
Raw Normal View History

package main
import (
2013-03-27 20:30:24 +00:00
"io/ioutil"
"launchpad.net/goyaml"
)
type Config map[string]interface{}
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
}
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
}
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-03-27 20:30:24 +00:00
err = goyaml.Unmarshal(bytes, &config)
if err != nil {
return
}
2013-03-27 20:30:24 +00:00
return config, nil
}
func WriteConfigFile(filename string, data []byte) (err error) {
2013-03-27 20:30:24 +00:00
return
}