fix: remove testing code, fix version print, change watch conf place

This commit is contained in:
Muyao CHEN 2024-10-02 23:26:42 +02:00
parent 792ee4ebe0
commit e45f4d992f
3 changed files with 8 additions and 16 deletions

View File

@ -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())
}

View File

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

View File

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