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:
parent
ae688c93a9
commit
a403845f58
2 changed files with 10 additions and 4 deletions
|
@ -1,4 +1,4 @@
|
||||||
package main
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
@ -7,6 +7,7 @@ import (
|
||||||
|
|
||||||
type Config map[string]interface{}
|
type Config map[string]interface{}
|
||||||
|
|
||||||
|
// Of the configurations, provided option, return the value as a bool
|
||||||
func (c *Config) GetBool(option string) (value bool) {
|
func (c *Config) GetBool(option string) (value bool) {
|
||||||
conf := Config{}
|
conf := Config{}
|
||||||
conf = *c
|
conf = *c
|
||||||
|
@ -19,6 +20,7 @@ func (c *Config) GetBool(option string) (value bool) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Of the configurations, provided option, return the value as a string
|
||||||
func (c *Config) GetString(option string) (value string) {
|
func (c *Config) GetString(option string) (value string) {
|
||||||
conf := Config{}
|
conf := Config{}
|
||||||
conf = *c
|
conf = *c
|
||||||
|
@ -26,6 +28,7 @@ func (c *Config) GetString(option string) (value string) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Given a filename to a YAML file, unmarshal it, and return a Config
|
||||||
func ReadConfigFile(filename string) (config Config, err error) {
|
func ReadConfigFile(filename string) (config Config, err error) {
|
||||||
bytes, err := ioutil.ReadFile(filename)
|
bytes, err := ioutil.ReadFile(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -40,6 +43,8 @@ func ReadConfigFile(filename string) (config Config, err error) {
|
||||||
return config, nil
|
return config, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
func WriteConfigFile(filename string, data []byte) (err error) {
|
func WriteConfigFile(filename string, data []byte) (err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
*/
|
|
@ -10,6 +10,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/vbatts/imgsrv/config"
|
||||||
"github.com/vbatts/imgsrv/client"
|
"github.com/vbatts/imgsrv/client"
|
||||||
"github.com/vbatts/imgsrv/util"
|
"github.com/vbatts/imgsrv/util"
|
||||||
"labix.org/v2/mgo"
|
"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)
|
//log.Printf("Attempting to load config file: %s", filename)
|
||||||
c, err := ReadConfigFile(filename)
|
c, err := config.ReadConfigFile(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
//log.Println(err)
|
//log.Println(err)
|
||||||
return Config{}
|
return config.Config{}
|
||||||
}
|
}
|
||||||
|
|
||||||
cRunAsServer := c.GetBool("server")
|
cRunAsServer := c.GetBool("server")
|
||||||
|
|
Loading…
Reference in a new issue