Skip to content

beijibeijing/viper

 
 

Repository files navigation

NEW Watching and re-reading config files

use github.com/radovskyb/watcher to Watching and re-reading config files,so it could work in k8s.

viper.WatcherConfig()
viper.OnWatcherConfigChange(func(e watcher.Event) {
	fmt.Println("Config file changed:", e.FileInfo)
})

Old Watching and re-reading config files

Viper supports the ability to have your application live read a config file while running.

Gone are the days of needing to restart a server to have a config take effect, viper powered applications can read an update to a config file while running and not miss a beat.

Simply tell the viper instance to watchConfig. Optionally you can provide a function for Viper to run each time a change occurs.

Make sure you add all of the configPaths prior to calling WatchConfig()

viper.WatchConfig()
viper.OnConfigChange(func(e fsnotify.Event) {
	fmt.Println("Config file changed:", e.Name)
})

About

Go configuration with fangs

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 98.3%
  • Makefile 1.7%