当前位置: 首页>>代码示例>>Golang>>正文


Golang viper.BindEnv函数代码示例

本文整理汇总了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)
}
开发者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


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