aboutsummaryrefslogtreecommitdiff
path: root/server/config
diff options
context:
space:
mode:
authorNiall Sheridan <nsheridan@gmail.com>2016-04-23 18:04:09 +0100
committerNiall Sheridan <nsheridan@gmail.com>2016-04-23 18:04:09 +0100
commit19125034df9d17e0eec70fd8be76d785648232b1 (patch)
tree0763fc763058c2d827ba70d946df900e5e81bc13 /server/config
parentbbca1c033649c178475671b5be6133a92e0f9bc1 (diff)
Refactor to use an io.Reader for easier testing
Diffstat (limited to 'server/config')
-rw-r--r--server/config/config.go12
1 files changed, 8 insertions, 4 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 {