From 3b18b32fd3d5a583162186ff8e8d4b1e63224e3e Mon Sep 17 00:00:00 2001 From: glebik000 <58261400+glebik000@users.noreply.github.com> Date: Sun, 20 Nov 2022 00:01:02 +1000 Subject: [PATCH 1/3] Add DocBlock to WatchConfig Added a small description of the WatchConfig(). So that you can understand in the ide why you could use it. --- viper.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/viper.go b/viper.go index 5c12529b4..99d46f07e 100644 --- a/viper.go +++ b/viper.go @@ -421,13 +421,18 @@ var SupportedExts = []string{"json", "toml", "yaml", "yml", "properties", "props // SupportedRemoteProviders are universally supported remote providers. var SupportedRemoteProviders = []string{"etcd", "etcd3", "consul", "firestore"} +// OnConfigChange is used to implement a response on config files change. func OnConfigChange(run func(in fsnotify.Event)) { v.OnConfigChange(run) } func (v *Viper) OnConfigChange(run func(in fsnotify.Event)) { v.onConfigChange = run } +// WatchConfig is watching changes on config files +// to start event in OnConfigChange. Used for global viper config. func WatchConfig() { v.WatchConfig() } +// WatchConfig is watching changes on config files +// to start event in OnConfigChange. func (v *Viper) WatchConfig() { initWG := sync.WaitGroup{} initWG.Add(1) From 6c4d3597454258f58eb1e0eb28072553299be275 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rk=20S=C3=A1gi-Kaz=C3=A1r?= Date: Thu, 19 Jan 2023 16:24:08 +0100 Subject: [PATCH 2/3] Update viper.go --- viper.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/viper.go b/viper.go index 99d46f07e..c33fb6276 100644 --- a/viper.go +++ b/viper.go @@ -421,18 +421,16 @@ var SupportedExts = []string{"json", "toml", "yaml", "yml", "properties", "props // SupportedRemoteProviders are universally supported remote providers. var SupportedRemoteProviders = []string{"etcd", "etcd3", "consul", "firestore"} -// OnConfigChange is used to implement a response on config files change. +// OnConfigChange sets the event handler that is called when a config file changes. func OnConfigChange(run func(in fsnotify.Event)) { v.OnConfigChange(run) } func (v *Viper) OnConfigChange(run func(in fsnotify.Event)) { v.onConfigChange = run } -// WatchConfig is watching changes on config files -// to start event in OnConfigChange. Used for global viper config. +// WatchConfig starts watching a config file for changes. func WatchConfig() { v.WatchConfig() } -// WatchConfig is watching changes on config files -// to start event in OnConfigChange. +// WatchConfig starts watching a config file for changes. func (v *Viper) WatchConfig() { initWG := sync.WaitGroup{} initWG.Add(1) From fefe35c98fda9ff00f2ebc7f96be5c91e01ebabb Mon Sep 17 00:00:00 2001 From: Mark Sagi-Kazar Date: Thu, 19 Jan 2023 16:31:34 +0100 Subject: [PATCH 3/3] update viper.go Signed-off-by: Mark Sagi-Kazar --- viper.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/viper.go b/viper.go index c33fb6276..06610fc5a 100644 --- a/viper.go +++ b/viper.go @@ -423,6 +423,8 @@ var SupportedRemoteProviders = []string{"etcd", "etcd3", "consul", "firestore"} // OnConfigChange sets the event handler that is called when a config file changes. func OnConfigChange(run func(in fsnotify.Event)) { v.OnConfigChange(run) } + +// OnConfigChange sets the event handler that is called when a config file changes. func (v *Viper) OnConfigChange(run func(in fsnotify.Event)) { v.onConfigChange = run }