diff options
Diffstat (limited to 'server')
-rw-r--r-- | server/config/config.go | 12 | ||||
-rw-r--r-- | server/main.go | 12 |
2 files changed, 19 insertions, 5 deletions
diff --git a/server/config/config.go b/server/config/config.go index e6f1822..21fba94 100644 --- a/server/config/config.go +++ b/server/config/config.go @@ -1,6 +1,10 @@ package config -import "github.com/spf13/viper" +import ( + "io" + + "github.com/spf13/viper" +) // Config holds the values from the json config file. type Config struct { @@ -37,11 +41,11 @@ type SSH struct { } // ReadConfig parses a JSON configuration file into a Config struct. -func ReadConfig(filename string) (*Config, error) { +func ReadConfig(r io.Reader) (*Config, error) { config := &Config{} v := viper.New() - v.SetConfigFile(filename) - if err := v.ReadInConfig(); err != nil { + v.SetConfigType("json") + if err := v.ReadConfig(r); err != nil { return nil, err } if err := v.Unmarshal(config); err != nil { diff --git a/server/main.go b/server/main.go index c597b2e..4f1cbd6 100644 --- a/server/main.go +++ b/server/main.go @@ -12,6 +12,7 @@ import ( "io/ioutil" "log" "net/http" + "os" "time" "golang.org/x/oauth2" @@ -203,9 +204,18 @@ func newState() string { return hex.EncodeToString(k) } +func readConfig(filename string) (*config.Config, error) { + f, err := os.Open(filename) + if err != nil { + return nil, err + } + defer f.Close() + return config.ReadConfig(f) +} + func main() { flag.Parse() - config, err := config.ReadConfig(*cfg) + config, err := readConfig(*cfg) if err != nil { log.Fatal(err) } |