summaryrefslogtreecommitdiffstats
path: root/bridge/config
diff options
context:
space:
mode:
authorWim <wim@42.be>2018-11-08 00:26:13 +0100
committerWim <wim@42.be>2018-11-08 00:26:13 +0100
commit0ededb88633cd5d93665c250b49ea4f598a1a793 (patch)
tree4c398677da3e18b2f486607c6eb1b07f097a5799 /bridge/config
parentaa59bb1a416b9bbdfc09c9d1dc23d9d97dbe8d50 (diff)
parentf2703979a47ce21792fbb4398bcc241e86beab6d (diff)
downloadmatterbridge-msglm-0ededb88633cd5d93665c250b49ea4f598a1a793.tar.gz
matterbridge-msglm-0ededb88633cd5d93665c250b49ea4f598a1a793.tar.bz2
matterbridge-msglm-0ededb88633cd5d93665c250b49ea4f598a1a793.zip
Merge branch 'master' of github.com:42wim/matterbridge
Diffstat (limited to 'bridge/config')
-rw-r--r--bridge/config/config.go40
1 files changed, 18 insertions, 22 deletions
diff --git a/bridge/config/config.go b/bridge/config/config.go
index 5ccf6041..bdf77f88 100644
--- a/bridge/config/config.go
+++ b/bridge/config/config.go
@@ -2,7 +2,7 @@ package config
import (
"bytes"
- "os"
+ "io/ioutil"
"strings"
"sync"
"time"
@@ -183,42 +183,38 @@ type Config struct {
func NewConfig(cfgfile string) *Config {
log.SetFormatter(&prefixed.TextFormatter{PrefixPadding: 13, DisableColors: true, FullTimestamp: false})
flog := log.WithFields(log.Fields{"prefix": "config"})
- var cfg ConfigValues
- viper.SetConfigType("toml")
viper.SetConfigFile(cfgfile)
- viper.SetEnvPrefix("matterbridge")
- viper.AddConfigPath(".")
- viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_", "-", "_"))
- viper.AutomaticEnv()
- f, err := os.Open(cfgfile)
+ input, err := getFileContents(cfgfile)
if err != nil {
log.Fatal(err)
}
- err = viper.ReadConfig(f)
- if err != nil {
- log.Fatal(err)
- }
- err = viper.Unmarshal(&cfg)
- if err != nil {
- log.Fatal("blah", err)
- }
- mycfg := new(Config)
- mycfg.v = viper.GetViper()
- if cfg.General.MediaDownloadSize == 0 {
- cfg.General.MediaDownloadSize = 1000000
+ mycfg := NewConfigFromString(input)
+ if mycfg.ConfigValues.General.MediaDownloadSize == 0 {
+ mycfg.ConfigValues.General.MediaDownloadSize = 1000000
}
viper.WatchConfig()
viper.OnConfigChange(func(e fsnotify.Event) {
flog.Println("Config file changed:", e.Name)
})
-
- mycfg.ConfigValues = &cfg
return mycfg
}
+func getFileContents(filename string) ([]byte, error) {
+ input, err := ioutil.ReadFile(filename)
+ if err != nil {
+ log.Fatal(err)
+ return []byte(nil), err
+ }
+ return input, nil
+}
+
func NewConfigFromString(input []byte) *Config {
var cfg ConfigValues
viper.SetConfigType("toml")
+ viper.SetEnvPrefix("matterbridge")
+ viper.AddConfigPath(".")
+ viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_", "-", "_"))
+ viper.AutomaticEnv()
err := viper.ReadConfig(bytes.NewBuffer(input))
if err != nil {
log.Fatal(err)