當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。