diff --git a/config.go b/config/config.go similarity index 75% rename from config.go rename to config/config.go index 62ce0f2..6971e18 100644 --- a/config.go +++ b/config/config.go @@ -1,4 +1,4 @@ -package main +package config import ( "io/ioutil" @@ -7,6 +7,7 @@ import ( 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 @@ -19,6 +20,7 @@ func (c *Config) GetBool(option string) (value bool) { return } +// Of the configurations, provided option, return the value as a string func (c *Config) GetString(option string) (value string) { conf := Config{} conf = *c @@ -26,6 +28,7 @@ func (c *Config) GetString(option string) (value 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 { @@ -40,6 +43,8 @@ func ReadConfigFile(filename string) (config Config, err error) { return config, nil } +/* func WriteConfigFile(filename string, data []byte) (err error) { return } +*/ diff --git a/imgsrv.go b/imgsrv.go index e1138b3..d1242f4 100644 --- a/imgsrv.go +++ b/imgsrv.go @@ -10,6 +10,7 @@ package main import ( "flag" "fmt" + "github.com/vbatts/imgsrv/config" "github.com/vbatts/imgsrv/client" "github.com/vbatts/imgsrv/util" "labix.org/v2/mgo" @@ -161,12 +162,12 @@ func init() { } -func loadConfiguration(filename string) (c Config) { +func loadConfiguration(filename string) (c config.Config) { //log.Printf("Attempting to load config file: %s", filename) - c, err := ReadConfigFile(filename) + c, err := config.ReadConfigFile(filename) if err != nil { //log.Println(err) - return Config{} + return config.Config{} } cRunAsServer := c.GetBool("server")