From aa1d238b4efbf5134adc99da22e755e3aed2221d Mon Sep 17 00:00:00 2001 From: Muyao CHEN Date: Tue, 1 Oct 2024 21:58:57 +0200 Subject: [PATCH] feat: watch config reloading --- internal/howmuch/howmuch.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/internal/howmuch/howmuch.go b/internal/howmuch/howmuch.go index 203aea6..f6829cf 100644 --- a/internal/howmuch/howmuch.go +++ b/internal/howmuch/howmuch.go @@ -27,6 +27,7 @@ import ( "fmt" "net/http" + "github.com/fsnotify/fsnotify" "github.com/gin-gonic/gin" "github.com/spf13/cobra" "github.com/spf13/viper" @@ -79,6 +80,12 @@ func run() error { settings, _ := json.MarshalIndent(viper.AllSettings(), "", " ") + // watching reloading conf + viper.OnConfigChange(func(e fsnotify.Event) { + fmt.Println("Config file changed:", e.Name) + }) + viper.WatchConfig() + fmt.Println(string(settings)) fmt.Println(viper.GetString("db.username"))