fix: remove testing code, fix version print, change watch conf place
This commit is contained in:
parent
792ee4ebe0
commit
e45f4d992f
@ -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())
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user