From cc70319ebcf88e363e1b065b24a904315f523d69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Mon, 11 Jan 2016 13:34:45 +0100 Subject: [PATCH] Fix config watch * Only add *the* config file, not all possible folders * Trigger reload on both write and create events; the latter is what we get from atomic save editors (like TextMate) once https://github.com/go-fsnotify/fsnotify/pull/111 is merged See #142 --- viper.go | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/viper.go b/viper.go index 389a58e..68ebf8c 100644 --- a/viper.go +++ b/viper.go @@ -242,7 +242,7 @@ func (v *Viper) WatchConfig() { for { select { case event := <-watcher.Events: - if event.Op&fsnotify.Write == fsnotify.Write { + if event.Op&fsnotify.Write == fsnotify.Write || event.Op&fsnotify.Create == fsnotify.Create { err := v.ReadInConfig() if err != nil { log.Println("error:", err) @@ -255,16 +255,7 @@ func (v *Viper) WatchConfig() { } }() - if v.configFile != "" { - watcher.Add(v.configFile) - } else { - for _, x := range v.configPaths { - err = watcher.Add(x) - if err != nil { - log.Fatal(err) - } - } - } + watcher.Add(v.getConfigFile()) <-done }() }