From e45f4d992feacfc384ce32e4238553fca271d518 Mon Sep 17 00:00:00 2001 From: Muyao CHEN Date: Wed, 2 Oct 2024 23:26:42 +0200 Subject: [PATCH] fix: remove testing code, fix version print, change watch conf place --- internal/howmuch/helpers.go | 7 +++++++ internal/howmuch/howmuch.go | 15 --------------- pkg/version/verflag/verflag.go | 2 +- 3 files changed, 8 insertions(+), 16 deletions(-) diff --git a/internal/howmuch/helpers.go b/internal/howmuch/helpers.go index 17c4359..73d7b16 100644 --- a/internal/howmuch/helpers.go +++ b/internal/howmuch/helpers.go @@ -28,6 +28,7 @@ import ( "strings" "git.vinchent.xyz/vinchent/howmuch/internal/pkg/log" + "github.com/fsnotify/fsnotify" "github.com/spf13/cobra" "github.com/spf13/viper" ) @@ -68,6 +69,12 @@ func initConfig() { return } + // watching reloading conf + viper.OnConfigChange(func(e fsnotify.Event) { + log.InfoLog("Config file changed:", e.Name) + }) + viper.WatchConfig() + log.DebugLog("Using config file", "file", viper.ConfigFileUsed()) } diff --git a/internal/howmuch/howmuch.go b/internal/howmuch/howmuch.go index 06cb1b1..e5ff482 100644 --- a/internal/howmuch/howmuch.go +++ b/internal/howmuch/howmuch.go @@ -23,13 +23,11 @@ package howmuch import ( - "encoding/json" "fmt" "net/http" "git.vinchent.xyz/vinchent/howmuch/internal/pkg/log" "git.vinchent.xyz/vinchent/howmuch/pkg/version/verflag" - "github.com/fsnotify/fsnotify" "github.com/gin-gonic/gin" "github.com/spf13/cobra" "github.com/spf13/viper" @@ -89,19 +87,6 @@ to share their expense of an event or a trip`, } func run() error { - log.DebugLog("How much do I owe you?") - - settings, _ := json.MarshalIndent(viper.AllSettings(), "", " ") - - // watching reloading conf - viper.OnConfigChange(func(e fsnotify.Event) { - log.InfoLog("Config file changed:", e.Name) - }) - viper.WatchConfig() - - log.InfoLog(string(settings)) - log.InfoLog(viper.GetString("db.username")) - isDev := viper.GetBool("dev-mode") if isDev { gin.SetMode(gin.DebugMode) diff --git a/pkg/version/verflag/verflag.go b/pkg/version/verflag/verflag.go index 6b85b74..68070df 100644 --- a/pkg/version/verflag/verflag.go +++ b/pkg/version/verflag/verflag.go @@ -41,8 +41,8 @@ func AddFlags(fs *pflag.FlagSet) { } func PrintVersion() { - fmt.Printf("%s\n", version.Get().String()) if *doPrint { + fmt.Printf("%s\n", version.Get().String()) os.Exit(0) } }