(cfgFile) // } // viper.SetConfigName(".demo") // name of config file (without extension) // viper.AddConfigPath("$HOME") // adding home directory as first search path // viper.AutomaticEnv() // read in environment variables that match // // If a config file is found, read ...
这里的问题是.env中的键不正确。默认的键分隔符是.(参见源代码)。因此键应该是DATABASE.CONNECTIONURI...
Now that we’ve explored the application structure, the first thing we need to do is replace thego-quick/configpackage with Viper. Since the current package pulls configurations from Environment Variables, we will initially set up Viper to do the same thing. Once that's working, we will move...
log.Fatalf("can't load environment app.env: %v", err) } fmt.Printf(" ---%s---\n", "Reading Environment variables Using Viper package") fmt.Printf(" %s = %v \n", "Application_Environment", config.AppEnv) // not defined fmt.Printf(" %s = %s \n", "DB_DRIVE", dbDrive) fm...
viper.SetConfigName(".demo")// name of config file (without extension)viper.AddConfigPath("$HOME")// adding home directory as first search pathviper.AutomaticEnv()// read in environment variables that match// If a config file is found, read it in.iferr := viper.ReadInConfig(); err ...
viper.SetConfigName(".demo")// name of config file (without extension)viper.AddConfigPath("$HOME")// adding home directory as first search pathviper.AutomaticEnv()// read in environment variables that match// If a config file is found, read it in.iferr := viper.ReadInConfig(); err ...
viper.SetConfigName(".demo")// name of config file (without extension)viper.AddConfigPath("$HOME")// adding home directory as first search pathviper.AutomaticEnv()// read in environment variables that match// If a config file is found, read it in.iferr := viper.ReadInConfig(); err ...
viper.AddConfigPath(home) viper.SetConfigName(".smartant-cli") } viper.AutomaticEnv()// read in environment variables that match // If a config file is found, read it in. iferr:=viper.ReadInConfig();err==nil{ fmt.Println("Using config file:",viper.ConfigFileUsed()) ...
Working with Environment Variables Viper has full support for environment variables. This enables 12 factor applications out of the box. There are five methods that exist to aid working with ENV: AutomaticEnv() BindEnv(string...) : error SetEnvPrefix(string) SetEnvKeyReplacer(string...) *stri...
envconfig- Read your configuration from environment variables. gcfg- read INI-style configuration files into Go structs; supports user-defined types and subsections gofigure- Go application configuration made easy ini- Go package for read and write INI files ...