diff --git a/viper.go b/viper.go index e4bdda042..2888088d7 100644 --- a/viper.go +++ b/viper.go @@ -188,6 +188,8 @@ type Viper struct { experimentalFinder bool experimentalBindStruct bool + + watchConfigDelete bool } // New returns an initialized Viper instance. @@ -215,6 +217,7 @@ func New() *Viper { v.experimentalFinder = features.Finder v.experimentalBindStruct = features.BindStruct + v.watchConfigDelete = false return v } @@ -362,6 +365,10 @@ func (v *Viper) WatchConfig() { if v.onConfigChange != nil { v.onConfigChange(event) } + } else if filepath.Clean(event.Name) == configFile && event.Has(fsnotify.Remove) && v.GetWatchConfigDelete() { + if v.onConfigChange != nil { + v.onConfigChange(event) + } } else if filepath.Clean(event.Name) == configFile && event.Has(fsnotify.Remove) { eventsWG.Done() return @@ -404,6 +411,14 @@ func (v *Viper) SetEnvPrefix(in string) { } } +func (v *Viper) SetWatchConfigDelete(value bool) { + v.watchConfigDelete = value +} + +func (v *Viper) GetWatchConfigDelete() bool { + return v.watchConfigDelete +} + func GetEnvPrefix() string { return v.GetEnvPrefix() } func (v *Viper) GetEnvPrefix() string {