mirror of
https://github.com/vbatts/imgsrv.git
synced 2025-06-30 14:38:28 +00:00
moving the config handler out of the main set
This commit is contained in:
parent
ae688c93a9
commit
a403845f58
2 changed files with 10 additions and 4 deletions
50
config/config.go
Normal file
50
config/config.go
Normal file
|
@ -0,0 +1,50 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"launchpad.net/goyaml"
|
||||
)
|
||||
|
||||
type Config map[string]interface{}
|
||||
|
||||
// Of the configurations, provided option, return the value as a bool
|
||||
func (c *Config) GetBool(option string) (value bool) {
|
||||
conf := Config{}
|
||||
conf = *c
|
||||
switch conf[option] {
|
||||
default:
|
||||
value = false
|
||||
case "yes", "on", "true":
|
||||
value = true
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Of the configurations, provided option, return the value as a string
|
||||
func (c *Config) GetString(option string) (value string) {
|
||||
conf := Config{}
|
||||
conf = *c
|
||||
value, _ = conf[option].(string)
|
||||
return
|
||||
}
|
||||
|
||||
// Given a filename to a YAML file, unmarshal it, and return a Config
|
||||
func ReadConfigFile(filename string) (config Config, err error) {
|
||||
bytes, err := ioutil.ReadFile(filename)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = goyaml.Unmarshal(bytes, &config)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return config, nil
|
||||
}
|
||||
|
||||
/*
|
||||
func WriteConfigFile(filename string, data []byte) (err error) {
|
||||
return
|
||||
}
|
||||
*/
|
Loading…
Add table
Add a link
Reference in a new issue