feat: watch config reloading

This commit is contained in:
Muyao CHEN 2024-10-01 21:58:57 +02:00
parent 3d1d40b4fc
commit aa1d238b4e

View File

@ -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"))