• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang viper.BindEnv函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/spf13/viper.BindEnv函数的典型用法代码示例。如果您正苦于以下问题:Golang BindEnv函数的具体用法?Golang BindEnv怎么用?Golang BindEnv使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了BindEnv函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
}
开发者ID:GrappigPanda,项目名称:notorious,代码行数:27,代码来源:config.go


示例2: init

func init() {
	viper.SetEnvPrefix("vk")
	viper.BindEnv("token")
	viper.BindEnv("id")
	viper.BindEnv("mongo")
	viper.BindEnv("db")
}
开发者ID:cydev,项目名称:vk-common-groups,代码行数:7,代码来源:main.go


示例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)
	}
}
开发者ID:firecyberice,项目名称:demowebserver,代码行数:25,代码来源:main.go


示例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")
}
开发者ID:arrowcircle,项目名称:messenger,代码行数:8,代码来源:main.go


示例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")
}
开发者ID:Wodby,项目名称:wcli,代码行数:10,代码来源:main.go


示例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")
}
开发者ID:hyperboloide,项目名称:pdfgen,代码行数:12,代码来源:config.go


示例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")
}
开发者ID:programmerq,项目名称:notary,代码行数:12,代码来源:main.go


示例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", "")
}
开发者ID:SHMEDIALIMITED,项目名称:server,代码行数:13,代码来源:config.go


示例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)
}
开发者ID:yano3,项目名称:collector,代码行数:14,代码来源:watch.go


示例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")
}
开发者ID:klauern,项目名称:trackello,代码行数:50,代码来源:config.go


示例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
}
开发者ID:programmerq,项目名称:notary,代码行数:10,代码来源:main.go


示例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))
	}
}
开发者ID:breml,项目名称:mygoplayground,代码行数:12,代码来源:main.go


示例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)
}
开发者ID:ptrimble,项目名称:dreamhost-personal-backup,代码行数:29,代码来源:main.go


示例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()

}
开发者ID:SmartArduino,项目名称:wmc,代码行数:13,代码来源:wmc.go


示例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
		}
	}
}
开发者ID:golliher,项目名称:go-sharptv,代码行数:40,代码来源:sharptv.go


示例16: init

func init() {
	flag.StringVar(&config, "config", "config", "config name [.toml,.json,.yml]")
	flag.StringVar(&configpath, "configpath", ".", "config location")
	flag.Parse()

	//env
	viper.BindEnv("SERVER_MONGO_1_PORT_27017_TCP_ADDR")

	//setup config
	viper.AddConfigPath(configpath)
	viper.AddConfigPath("/")
	viper.SetConfigName(config)
	viper.ReadInConfig()
}
开发者ID:mikerjacobi,项目名称:poker,代码行数:14,代码来源:main.go


示例17: initByEnv

func initByEnv() {
	log.Println("init params by env..")
	viper.BindEnv("host", "HOST")
	viper.BindEnv("port", "PORT")
	viper.BindEnv("logLevel", "LOG_LEVEL")
	viper.BindEnv("cache.host", "CACHE_HOST")
	viper.BindEnv("cache.port", "CACHE_PORT")
	viper.BindEnv("cache.poolSize", "CACHE_POOLSIZE")
}
开发者ID:Dataman-Cloud,项目名称:seckilling,代码行数:9,代码来源:configuration.go


示例18: InitializeConfig

func InitializeConfig() {
	viper.SetConfigName("authcurl")
	viper.SetEnvPrefix("auth")

	viper.AddConfigPath("$HOME/.authcurl")
	viper.AddConfigPath("$HOME/.config/authcurl")
	viper.AddConfigPath("$HOME/.config")

	viper.SetDefault("Region", "us-east-1")
	viper.SetDefault("allow_insecure_ssl", false)
	viper.SetDefault("service", "")

	viper.BindEnv("region")
	viper.BindEnv("secret_key")
	viper.BindEnv("access_key")

	if authCmdV.PersistentFlags().Lookup("region").Changed {
		viper.Set("Region", Region)
	}

	if authCmdV.PersistentFlags().Lookup("access-key").Changed {
		viper.Set("access_key", AccessKey)
	}

	if authCmdV.PersistentFlags().Lookup("secret-key").Changed {
		viper.Set("secret_key", SecretKey)
	}

	if authCmdV.PersistentFlags().Lookup("service").Changed {
		viper.Set("service", Service)
	}

	if authCmdV.PersistentFlags().Lookup("allow-insecure-ssl").Changed {
		viper.Set("allow_insecure_ssl", AllowInsecureSsl)
	}
}
开发者ID:totallymike,项目名称:fetch,代码行数:36,代码来源:authcurl.go


示例19: initConfig

func initConfig() {
	viper.SetDefault("host", "localhost")
	viper.SetDefault("port", ":5090")
	viper.SetDefault("logLevel", "DEBUG")
	viper.SetDefault("watch", false)
	viper.SetDefault("cache.poolSize", 100)

	viper.BindEnv("init_model", "INIT_MODEL")
	model := viper.GetInt("init_model")
	switch model {
	case 0:
		initByConfigFile()
	case 1:
		initByEnv()
	default:
		initByConfigFile()
	}
}
开发者ID:Dataman-Cloud,项目名称:seckilling,代码行数:18,代码来源:configuration.go


示例20: main

func main() {
	// setup our settings
	viper.SetEnvPrefix("wmc")
	viper.BindEnv("serial")
	viper.SetDefault("serial", "/dev/ttyUSB0")

	var rootCmd = &cobra.Command{
		Use:   "wmc",
		Short: "wmc is a cross-platform command line utility for the WifiMCU Platform",
		Long: `wmc: ` + Version + `
wmc is a cross-platform command line utility for the WifiMCU Platform
GPL Licensed source code, downloads and issue tracker at
https://github.com/zpeters/wmc`,
	}
	rootCmd.AddCommand(cmdWmcVersion, cmdList, cmdPut, cmdRm, cmdConfig, cmdCommand, cmdRead, cmdRun, cmdReboot)
	rootCmd.PersistentFlags().BoolVarP(&Verbose, "verbose", "v", false, "verbose output")
	rootCmd.Execute()
}
开发者ID:zpeters,项目名称:wmc,代码行数:18,代码来源:wmc.go



注:本文中的github.com/spf13/viper.BindEnv函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang viper.BindPFlag函数代码示例发布时间:2022-05-28
下一篇:
Golang viper.AutomaticEnv函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap