feat: watch config reloading
This commit is contained in:
parent
3d1d40b4fc
commit
aa1d238b4e
@ -27,6 +27,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/fsnotify/fsnotify"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
@ -79,6 +80,12 @@ func run() error {
|
|||||||
|
|
||||||
settings, _ := json.MarshalIndent(viper.AllSettings(), "", " ")
|
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(string(settings))
|
||||||
fmt.Println(viper.GetString("db.username"))
|
fmt.Println(viper.GetString("db.username"))
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user