chore(storage): del init conf

This commit is contained in:
bandl 2021-09-05 15:00:39 +08:00
parent fd80e3ddde
commit 136fc48206
2 changed files with 8 additions and 47 deletions

View File

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

View File

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