From 136fc482065a974aa4306d47b1201f4af5ee8249 Mon Sep 17 00:00:00 2001 From: bandl <1658002533@qq.com> Date: Sun, 5 Sep 2021 15:00:39 +0800 Subject: [PATCH] chore(storage): del init conf --- storage/cmd/root.go | 51 +++++---------------------------------------- storage/main.go | 4 +++- 2 files changed, 8 insertions(+), 47 deletions(-) diff --git a/storage/cmd/root.go b/storage/cmd/root.go index d26625a..dc5f5a4 100644 --- a/storage/cmd/root.go +++ b/storage/cmd/root.go @@ -3,22 +3,19 @@ package cmd import ( "fmt" - "gitee.com/timedb/wheatCache/storage/proto" - "gitee.com/timedb/wheatCache/storage/server" - "github.com/spf13/cobra" - "google.golang.org/grpc" - "google.golang.org/grpc/reflection" "log" "net" "os" "os/signal" "syscall" - "github.com/spf13/viper" + "gitee.com/timedb/wheatCache/storage/proto" + "gitee.com/timedb/wheatCache/storage/server" + "github.com/spf13/cobra" + "google.golang.org/grpc" + "google.golang.org/grpc/reflection" ) -var cfgFile string - // rootCmd represents the base command when called without any subcommands var rootCmd = &cobra.Command{ Use: "storage", @@ -63,41 +60,3 @@ var rootCmd = &cobra.Command{ func Execute() { cobra.CheckErr(rootCmd.Execute()) } - -func init() { - cobra.OnInitialize(initConfig) - - // Here you will define your flags and configuration settings. - // Cobra supports persistent flags, which, if defined here, - // will be global for your application. - - rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.storage.yaml)") - - // Cobra also supports local flags, which will only run - // when this action is called directly. - rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") -} - -// initConfig reads in config file and ENV variables if set. -func initConfig() { - if cfgFile != "" { - // Use config file from the flag. - viper.SetConfigFile(cfgFile) - } else { - // Find home directory. - home, err := os.UserHomeDir() - cobra.CheckErr(err) - - // Search config in home directory with name ".storage" (without extension). - viper.AddConfigPath(home) - viper.SetConfigType("yaml") - viper.SetConfigName(".storage") - } - - viper.AutomaticEnv() // read in environment variables that match - - // If a config file is found, read it in. - if err := viper.ReadInConfig(); err == nil { - fmt.Fprintln(os.Stderr, "Using config file:", viper.ConfigFileUsed()) - } -} diff --git a/storage/main.go b/storage/main.go index caf97ea..15638de 100644 --- a/storage/main.go +++ b/storage/main.go @@ -15,7 +15,9 @@ limitations under the License. */ package main -import "gitee.com/timedb/wheatCache/storage/cmd" +import ( + "gitee.com/timedb/wheatCache/storage/cmd" +) func main() { cmd.Execute()