feat: watch config reloading
This commit is contained in:
parent
3d1d40b4fc
commit
7e876324a2
2
go.mod
2
go.mod
@ -3,6 +3,7 @@ module git.vinchent.xyz/vinchent/howmuch
|
||||
go 1.23.1
|
||||
|
||||
require (
|
||||
github.com/fsnotify/fsnotify v1.7.0
|
||||
github.com/gin-gonic/gin v1.10.0
|
||||
github.com/spf13/cobra v1.8.1
|
||||
github.com/spf13/viper v1.19.0
|
||||
@ -14,7 +15,6 @@ require (
|
||||
github.com/bytedance/sonic/loader v0.1.1 // indirect
|
||||
github.com/cloudwego/base64x v0.1.4 // indirect
|
||||
github.com/cloudwego/iasm v0.2.0 // indirect
|
||||
github.com/fsnotify/fsnotify v1.7.0 // indirect
|
||||
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
|
||||
github.com/gin-contrib/sse v0.1.0 // indirect
|
||||
github.com/go-playground/locales v0.14.1 // indirect
|
||||
|
@ -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"))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user