From 96a47a60adc3301106c3f27c39c0ba03e2ebe177 Mon Sep 17 00:00:00 2001 From: Wim Date: Tue, 1 May 2018 22:23:37 +0200 Subject: Add support for reloading all settings automatically after changing config except connection and gateway configuration. Closes #373 --- bridge/config/config.go | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'bridge') diff --git a/bridge/config/config.go b/bridge/config/config.go index 09f15c2e..1b92f83c 100644 --- a/bridge/config/config.go +++ b/bridge/config/config.go @@ -2,8 +2,10 @@ package config import ( "bytes" + "github.com/fsnotify/fsnotify" log "github.com/sirupsen/logrus" "github.com/spf13/viper" + prefixed "github.com/x-cray/logrus-prefixed-formatter" "os" "strings" "sync" @@ -169,9 +171,13 @@ 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) @@ -191,6 +197,11 @@ func NewConfig(cfgfile string) *Config { if cfg.General.MediaDownloadSize == 0 { cfg.General.MediaDownloadSize = 1000000 } + viper.WatchConfig() + viper.OnConfigChange(func(e fsnotify.Event) { + flog.Println("Config file changed:", e.Name) + }) + mycfg.ConfigValues = &cfg return mycfg } -- cgit v1.2.3