本文整理汇总了Golang中github.com/spf13/viper.BindEnv函数的典型用法代码示例。如果您正苦于以下问题:Golang BindEnv函数的具体用法?Golang BindEnv怎么用?Golang BindEnv使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了BindEnv函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: LoadConfig
// LoadConfig loads the config into the Config Struct and returns the // ConfigStruct object. Will load from environmental variables (all caps) if we
// set a flag to true.
func LoadConfig() ConfigStruct {
viper.SetConfigName("config")
viper.SetConfigType("yaml")
viper.AddConfigPath(".")
viper.AddConfigPath("../")
viper.AddConfigPath("/etc/")
viper.AddConfigPath("$GOPATH/src/github.com/GrappigPanda/notorious/")
err := viper.ReadInConfig()
if err != nil {
panic("Failed to open config file")
}
if viper.GetBool("UseEnvVariables") == true {
viper.AutomaticEnv()
viper.BindEnv("dbuser")
}
whitelist, err := strconv.ParseBool(viper.Get("whitelist").(string))
if err != nil {
whitelist = false
}
return loadSQLOptions(whitelist)
}
示例2: init
func init() {
viper.SetEnvPrefix("vk")
viper.BindEnv("token")
viper.BindEnv("id")
viper.BindEnv("mongo")
viper.BindEnv("db")
}
示例3: init
func init() {
// default values
// If no config is found, use the default(s)
viper.SetDefault("port", 80)
viper.SetDefault("crate_rest_api", "")
viper.SetDefault("crate", false)
// environment variable
viper.SetEnvPrefix("fci") // will be uppercased automatically
viper.BindEnv("port")
viper.BindEnv("crate")
viper.BindEnv("crate_rest_api")
// config file
viper.AddConfigPath("./")
viper.SetConfigName("config")
err := viper.ReadInConfig()
// check if configfile is available
if err != nil {
fmt.Println("No configuration file loaded")
// os.Exit(1)
}
}
示例4: readConfig
func readConfig() {
viper.SetEnvPrefix("chat")
viper.SetDefault("database_url", "postgres:///chat_development?sslmode=disable")
viper.SetDefault("bind_address", "localhost:8080")
viper.AutomaticEnv()
viper.BindEnv("database_url")
viper.BindEnv("bind_address")
}
示例5: init
func init() {
viper.SetDefault("docroot", "/srv/docroot")
viper.SetEnvPrefix("wodby")
viper.BindEnv("app_type")
viper.BindEnv("app_version")
viper.BindEnv("environment_type")
viper.BindEnv("environment_name")
viper.BindEnv("namespace")
}
示例6: init
func init() {
viper.SetEnvPrefix("pdfgen")
viper.BindEnv("port")
viper.SetDefault("port", "8888")
viper.BindEnv("addr")
viper.SetDefault("addr", "0.0.0.0")
viper.BindEnv("templates")
viper.SetDefault("templates", "./templates")
}
示例7: init
func init() {
// set default log level to Error
viper.SetDefault("logging", map[string]interface{}{"level": 2})
viper.SetEnvPrefix(_EnvPrefix)
viper.BindEnv(_DefaultAliasEnv)
viper.BindEnv(_PINCode)
// Setup flags
flag.StringVar(&configFile, "config", "", "Path to configuration file")
flag.BoolVar(&debug, "debug", false, "show the version and exit")
}
示例8: setupEnvVars
func setupEnvVars() {
viper.SetEnvPrefix("mb")
viper.BindEnv("env")
viper.SetDefault("env", "development")
viper.BindEnv("loglevel")
viper.SetDefault("loglevel", "info")
viper.BindEnv("host")
viper.SetDefault("host", "localhost:7777")
viper.BindEnv("redis_host")
viper.SetDefault("redis_host", "localhost:6379")
viper.BindEnv("redis_password")
viper.SetDefault("redis_password", "")
}
示例9: init
func init() {
RootCmd.AddCommand(watchCmd)
watchCmd.Flags().StringVarP(&hostedZone, "hosted-zone", "H", "", "Hosted zone to update")
watchCmd.Flags().StringVarP(&checkID, "check-id", "C", "", "CheckID to use for IP output")
watchCmd.Flags().StringSliceVarP(&domains, "domain", "D", []string{}, "Full domain name to keep global IPs")
viper.SetEnvPrefix("collector")
viper.BindEnv("hosted_zone")
viper.BindEnv("check_id")
viper.BindEnv("domain")
cobra.OnInitialize(initEnviron)
}
示例10: init
// TODO: Need to look at whether this is just too much going on.
func init() {
// enable ability to specify config file via flag
RootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.trackello.yaml)")
if cfgFile != "" {
viper.SetConfigFile(cfgFile)
}
viper.SetConfigName(".trackello") // name of config file (without extension)
// Set Environment Variables
viper.SetEnvPrefix("trackello")
viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_")) // replace environment variables to underscore (_) from hyphen (-)
if err := viper.BindEnv("appkey", trackello.TRACKELLO_APPKEY); err != nil {
panic(err)
}
if err := viper.BindEnv("token", trackello.TRACKELLO_TOKEN); err != nil {
panic(err)
}
if err := viper.BindEnv("board", trackello.TRACKELLO_PREFERRED_BOARD); err != nil {
panic(err)
}
viper.AutomaticEnv() // read in environment variables that match every time Get() is called
// Add Configuration Paths
if cwd, err := os.Getwd(); err == nil {
viper.AddConfigPath(cwd)
}
viper.AddConfigPath("$HOME") // adding home directory as first search path
// If a config file is found, read it in.
if err := viper.ReadInConfig(); err == nil {
fmt.Println("Using config file:", viper.ConfigFileUsed())
}
RootCmd.AddCommand(configCmd)
RootCmd.PersistentFlags().StringVar(&trelloAppKey, "appkey", "", "Trello Application Key")
if err := viper.BindPFlag("appkey", RootCmd.PersistentFlags().Lookup("appkey")); err != nil {
panic(err)
}
RootCmd.PersistentFlags().StringVar(&trelloToken, "token", "", "Trello Token")
if err := viper.BindPFlag("token", RootCmd.PersistentFlags().Lookup("token")); err != nil {
panic(err)
}
RootCmd.PersistentFlags().StringVar(&preferredBoard, "board", "", "Preferred Board ID")
if err := viper.BindPFlag("board", RootCmd.PersistentFlags().Lookup("board")); err != nil {
panic(err)
}
viper.RegisterAlias("preferredBoard", "board")
}
示例11: passphraseRetriever
func passphraseRetriever(keyName, alias string, createNew bool, attempts int) (passphrase string, giveup bool, err error) {
viper.BindEnv(alias)
passphrase = viper.GetString(strings.ToUpper(alias))
if passphrase == "" {
return "", false, errors.New("expected env variable to not be empty: " + alias)
}
return passphrase, false, nil
}
示例12: init
func init() {
viper.SetEnvPrefix("snake")
viper.BindEnv("target")
viper.SetConfigName("config")
viper.AddConfigPath("/etc/snake/")
viper.AddConfigPath("$HOME/.snake")
viper.AddConfigPath(".")
err := viper.ReadInConfig() // Find and read the config file
if err != nil { // Handle errors reading the config file
panic(fmt.Errorf("Fatal error config file: %s \n", err))
}
}
示例13: processVars
func processVars() {
flag.String("targetDirs", "", "Local directories to back up.")
flag.String("s3Host", "", "S3 host.")
flag.String("s3AccessKey", "", "S3 access key.")
flag.String("s3SecretKey", "", "S3 secret key.")
flag.String("s3BucketName", "", "S3 Bucket Name.")
flag.Int("remoteWorkerCount", 5, "Number of workers performing actions against S3 host.")
flag.Bool("dryRun", false, "Flag to indicate that this should be a dry run.")
flag.Parse()
viper.BindPFlag("targetDirs", flag.CommandLine.Lookup("targetDirs"))
viper.BindPFlag("s3Host", flag.CommandLine.Lookup("s3Host"))
viper.BindPFlag("s3AccessKey", flag.CommandLine.Lookup("s3AccessKey"))
viper.BindPFlag("s3SecretKey", flag.CommandLine.Lookup("s3SecretKey"))
viper.BindPFlag("s3BucketName", flag.CommandLine.Lookup("s3BucketName"))
viper.BindPFlag("remoteWorkerCount", flag.CommandLine.Lookup("remoteWorkerCount"))
viper.BindPFlag("dryRun", flag.CommandLine.Lookup("dryRun"))
viper.AutomaticEnv()
viper.SetEnvPrefix("PERSONAL_BACKUP")
viper.BindEnv("targetDirs")
viper.BindEnv("s3Host")
viper.BindEnv("s3AccessKey")
viper.BindEnv("s3SecretKey")
viper.BindEnv("s3BucketName")
viper.BindEnv("remoteWorkerCount")
viper.SetDefault("remoteWorkerCount", 5)
}
示例14: main
func main() {
fmt.Printf("Version: %s\n", Version)
// setup our settings
viper.SetEnvPrefix("wmc")
viper.BindEnv("serial")
viper.SetDefault("serial", "/dev/ttyUSB0")
var rootCmd = &cobra.Command{}
rootCmd.AddCommand(cmdWmcVersion, cmdList, cmdPut, cmdRm, cmdConfig, cmdVersion)
rootCmd.Execute()
}
示例15: InitializeConfig
// InitializeConfig loads our configuration using Viper package.
func InitializeConfig() {
// Set config file
viper.SetConfigName("config")
// Add config path
viper.AddConfigPath("$HOME/.sharptv")
// Read in the config
err := viper.ReadInConfig() // Find and read the config file
if err != nil { // Handle errors reading the config file
panic(fmt.Errorf("Fatal error config file: %s \n", err))
}
// Load default settings
viper.SetDefault("debug", false)
viper.SetEnvPrefix("gosharptv") // will be uppercased automatically
viper.BindEnv("debug")
viper.BindEnv("ip")
viper.BindEnv("port")
// Do some flag handling and any complicated config logic
if !viper.IsSet("ip") || !viper.IsSet("port") {
fmt.Println("Configuration error. Both IP and PORT must be set via either config, environment, or flags.")
os.Exit(1)
}
// TODO --implement the use of this data in the input command
inputLabelMap = make(map[string]int)
inputNames := []string{"input1", "input2", "input3", "input4", "input5", "input6", "input7", "input8"}
for i, v := range inputNames {
if viper.IsSet(v) {
inputname := viper.GetString(v)
inputLabelMap[inputname] = i + 1
}
}
}