1
0
Fork 0
mirror of https://github.com/vbatts/imgsrv.git synced 2024-11-23 16:45:39 +00:00

moving the config handler out of the main set

This commit is contained in:
Vincent Batts 2013-05-10 16:22:58 -04:00
parent ae688c93a9
commit a403845f58
2 changed files with 10 additions and 4 deletions

View file

@ -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
}
*/

View file

@ -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")