mirror of
https://github.com/spf13/viper
synced 2024-12-22 19:47:01 +00:00
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
This commit is contained in:
parent
0c82789feb
commit
cc70319ebc
1 changed files with 2 additions and 11 deletions
13
viper.go
13
viper.go
|
@ -242,7 +242,7 @@ func (v *Viper) WatchConfig() {
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case event := <-watcher.Events:
|
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()
|
err := v.ReadInConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("error:", err)
|
log.Println("error:", err)
|
||||||
|
@ -255,16 +255,7 @@ func (v *Viper) WatchConfig() {
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
if v.configFile != "" {
|
watcher.Add(v.getConfigFile())
|
||||||
watcher.Add(v.configFile)
|
|
||||||
} else {
|
|
||||||
for _, x := range v.configPaths {
|
|
||||||
err = watcher.Add(x)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
<-done
|
<-done
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue