From 1c6c5197336b76fef09778e072c9c5f985e1b7f1 Mon Sep 17 00:00:00 2001 From: leonz789 Date: Mon, 9 Sep 2024 11:19:30 +0800 Subject: [PATCH] reset configfile --- cmd/root.go | 23 ----------------------- types/types.go | 5 ++--- 2 files changed, 2 insertions(+), 26 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index b7f6454..240c881 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -59,21 +59,6 @@ func init() { // initConfig reads in config file and ENV variables if set. func initConfig() { - // v := viper.New() - // if cfgFile != "" { - // // Use config file from the flag. - // v.SetConfigFile(cfgFile) - // } else { - // // Find home directory. - // home, err := os.UserHomeDir() - // cobra.CheckErr(err) - // - // cfgFile = path.Join(home, ".price-feeder") - // // Search config in home directory with name ".price-feeder" (without extension). - // // v.AddConfigPath(home) - // // v.SetConfigType("yaml") - // // v.SetConfigName(".price-feeder") - // } if len(cfgFile) == 0 { // Find home directory. home, err := os.UserHomeDir() @@ -85,12 +70,4 @@ func initConfig() { types.ConfigFile = cfgFile conf = types.InitConfig(cfgFile) - - // // If a config file is found, read it in. - // - // if err := v.ReadInConfig(); err == nil { - // fmt.Fprintln(os.Stderr, "Using config file:", v.ConfigFileUsed()) - // } - // - // v.Unmarshal(&conf) } diff --git a/types/types.go b/types/types.go index 1edd02d..c527fc9 100644 --- a/types/types.go +++ b/types/types.go @@ -35,10 +35,9 @@ var ( func InitConfig(cfgFile string) Config { if v == nil { v = viper.New() - v.SetConfigFile(cfgFile) - v.SetConfigType("yaml") } - + v.SetConfigFile(cfgFile) + v.SetConfigType("yaml") // If a config file is found, read it in. if err := v.ReadInConfig(); err == nil { fmt.Fprintln(os.Stderr, "Using config file:", v.ConfigFileUsed())