本文整理汇总了Golang中github.com/spf13/viper.SetEnvKeyReplacer函数的典型用法代码示例。如果您正苦于以下问题:Golang SetEnvKeyReplacer函数的具体用法?Golang SetEnvKeyReplacer怎么用?Golang SetEnvKeyReplacer使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SetEnvKeyReplacer函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: InitConfig
func InitConfig() {
viper.SetConfigName("scds")
viper.SetConfigType("yaml")
viper.SetEnvPrefix("scds")
viper.AutomaticEnv()
// Replaces underscores with periods when mapping environment variables.
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
// Set non-zero defaults. Nested options take a lower precedence than
// dot-delimited ones, so namespaced options are defined here as maps.
viper.SetDefault("mongo", map[string]interface{}{
"uri": "localhost/scds",
})
viper.SetDefault("http", map[string]interface{}{
"host": "localhost",
"port": 5000,
})
viper.SetDefault("smtp", map[string]interface{}{
"host": "localhost",
"port": 25,
})
// Read the default config file from the working directory.
dir, err := os.Getwd()
if err != nil {
log.Fatal(err)
}
viper.AddConfigPath(dir)
}
示例2: init
func init() {
viper.SetConfigType("yaml")
viper.AutomaticEnv()
envReplacer := strings.NewReplacer(".", "_")
viper.SetEnvKeyReplacer(envReplacer)
}
示例3: Start
// Start entry point for chaincodes bootstrap.
func Start(cc Chaincode) error {
viper.SetEnvPrefix("OPENCHAIN")
viper.AutomaticEnv()
replacer := strings.NewReplacer(".", "_")
viper.SetEnvKeyReplacer(replacer)
flag.StringVar(&peerAddress, "peer.address", "", "peer address")
flag.Parse()
chaincodeLogger.Debug("Peer address: %s", getPeerAddress())
// Establish connection with validating peer
clientConn, err := newPeerClientConnection()
if err != nil {
chaincodeLogger.Error(fmt.Sprintf("Error trying to connect to local peer: %s", err))
return fmt.Errorf("Error trying to connect to local peer: %s", err)
}
chaincodeLogger.Debug("os.Args returns: %s", os.Args)
chaincodeSupportClient := pb.NewChaincodeSupportClient(clientConn)
err = chatWithPeer(chaincodeSupportClient, cc)
return err
}
示例4: Start
// Start entry point for chaincodes bootstrap.
func Start(cc Chaincode) error {
viper.SetEnvPrefix("OPENCHAIN")
viper.AutomaticEnv()
replacer := strings.NewReplacer(".", "_")
viper.SetEnvKeyReplacer(replacer)
/*
viper.SetConfigName("openchain") // name of config file (without extension)
viper.AddConfigPath("./../../../") // path to look for the config file in
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))
}
*/
fmt.Printf("peer.address: %s\n", getPeerAddress())
// Establish connection with validating peer
clientConn, err := newPeerClientConnection()
if err != nil {
return fmt.Errorf("Error trying to connect to local peer: %s", err)
}
fmt.Printf("os.Args returns: %s\n", os.Args)
chaincodeSupportClient := pb.NewChaincodeSupportClient(clientConn)
//err = c.Run(chaincodeSupportClient)
//if err != nil {
//}
// Handle message exchange with validating peer
err = chatWithPeer(chaincodeSupportClient, cc)
return err
}
示例5: Setup
// Setup sets up defaults for viper configuration options and
// overrides these values with the values from the given configuration file
// if it is not empty. Those values again are overwritten by environment
// variables.
func Setup(configFilePath string) error {
viper.Reset()
// Expect environment variables to be prefix with "ALMIGHTY_".
viper.SetEnvPrefix("ALMIGHTY")
// Automatically map environment variables to viper values
viper.AutomaticEnv()
// To override nested variables through environment variables, we
// need to make sure that we don't have to use dots (".") inside the
// environment variable names.
// To override foo.bar you need to set ALM_FOO_BAR
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
viper.SetTypeByDefaultValue(true)
setConfigDefaults()
// Read the config
// Explicitly specify which file to load config from
if configFilePath != "" {
viper.SetConfigFile(configFilePath)
viper.SetConfigType("yaml")
err := viper.ReadInConfig() // Find and read the config file
if err != nil { // Handle errors reading the config file
return fmt.Errorf("Fatal error config file: %s \n", err)
}
}
return nil
}
示例6: Start
// Start entry point for chaincodes bootstrap.
func Start(cc Chaincode) error {
viper.SetEnvPrefix("CORE")
viper.AutomaticEnv()
replacer := strings.NewReplacer(".", "_")
viper.SetEnvKeyReplacer(replacer)
flag.StringVar(&peerAddress, "peer.address", "", "peer address")
flag.Parse()
chaincodeLogger.Debug("Peer address: %s", getPeerAddress())
// Establish connection with validating peer
clientConn, err := newPeerClientConnection()
if err != nil {
chaincodeLogger.Error(fmt.Sprintf("Error trying to connect to local peer: %s", err))
return fmt.Errorf("Error trying to connect to local peer: %s", err)
}
chaincodeLogger.Debug("os.Args returns: %s", os.Args)
chaincodeSupportClient := pb.NewChaincodeSupportClient(clientConn)
// Establish stream with validating peer
stream, err := chaincodeSupportClient.Register(context.Background())
if err != nil {
return fmt.Errorf("Error chatting with leader at address=%s: %s", getPeerAddress(), err)
}
chaincodename := viper.GetString("chaincode.id.name")
err = chatWithPeer(chaincodename, stream, cc)
return err
}
示例7: main
func main() {
// For environment variables.
viper.SetEnvPrefix(cmdRoot)
viper.AutomaticEnv()
replacer := strings.NewReplacer(".", "_")
viper.SetEnvKeyReplacer(replacer)
// Define command-line flags that are valid for all peer commands and
// subcommands.
mainFlags := mainCmd.PersistentFlags()
mainFlags.BoolVarP(&versionFlag, "version", "v", false, "Display current version of fabric peer server")
mainFlags.String("logging-level", "", "Default logging level and overrides, see core.yaml for full syntax")
viper.BindPFlag("logging_level", mainFlags.Lookup("logging-level"))
testCoverProfile := ""
mainFlags.StringVarP(&testCoverProfile, "test.coverprofile", "", "coverage.cov", "Done")
var alternativeCfgPath = os.Getenv("PEER_CFG_PATH")
if alternativeCfgPath != "" {
logger.Infof("User defined config file path: %s", alternativeCfgPath)
viper.AddConfigPath(alternativeCfgPath) // Path to look for the config file in
} else {
viper.AddConfigPath("./") // Path to look for the config file in
// Path to look for the config file in based on GOPATH
gopath := os.Getenv("GOPATH")
for _, p := range filepath.SplitList(gopath) {
peerpath := filepath.Join(p, "src/github.com/hyperledger/fabric/peer")
viper.AddConfigPath(peerpath)
}
}
// Now set the configuration file.
viper.SetConfigName(cmdRoot) // Name of config file (without extension)
err := viper.ReadInConfig() // Find and read the config file
if err != nil { // Handle errors reading the config file
panic(fmt.Errorf("Fatal error when reading %s config file: %s\n", cmdRoot, err))
}
mainCmd.AddCommand(version.Cmd())
mainCmd.AddCommand(node.Cmd())
mainCmd.AddCommand(network.Cmd())
mainCmd.AddCommand(chaincode.Cmd())
runtime.GOMAXPROCS(viper.GetInt("peer.gomaxprocs"))
// Init the crypto layer
if err := crypto.Init(); err != nil {
panic(fmt.Errorf("Failed to initialize the crypto layer: %s", err))
}
// On failure Cobra prints the usage message and error string, so we only
// need to exit with a non-0 status
if mainCmd.Execute() != nil {
os.Exit(1)
}
logger.Info("Exiting.....")
}
示例8: init
func init() {
envReplacer = strings.NewReplacer(".", "_")
// Configure Viper to search for all configurations
// in the system environment variables
viper.SetEnvPrefix(envPrefix)
viper.AutomaticEnv()
viper.SetEnvKeyReplacer(envReplacer)
}
示例9: setupViper
func setupViper() {
viper.SetEnvPrefix(constants.MinikubeEnvPrefix)
// Replaces '-' in flags with '_' in env variables
// e.g. show-libmachine-logs => $ENVPREFIX_SHOW_LIBMACHINE_LOGS
viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))
viper.AutomaticEnv()
viper.SetDefault(config.WantUpdateNotification, true)
viper.SetDefault(config.ReminderWaitPeriodInHours, 24)
setFlagsUsingViper()
}
示例10: SetupCoreYAMLConfig
// SetupCoreYAMLConfig sets up configurations for testing
func SetupCoreYAMLConfig(coreYamlPath string) {
viper.SetConfigName("core")
viper.SetEnvPrefix("CORE")
viper.AddConfigPath(coreYamlPath)
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
viper.AutomaticEnv()
err := viper.ReadInConfig()
if err != nil { // Handle errors reading the config file
panic(fmt.Errorf("Fatal error config file: %s \n", err))
}
}
示例11: init
func init() {
// set default log level to Error
viper.SetDefault("logging", map[string]interface{}{"level": 2})
viper.SetEnvPrefix(envPrefix)
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
viper.AutomaticEnv()
// Setup flags
flag.StringVar(&configFile, "config", "", "Path to configuration file")
flag.BoolVar(&debug, "debug", false, "show the version and exit")
}
示例12: main
func main() {
rootCmd := &cobra.Command{
Use: "mantl-api",
Short: "runs the mantl-api",
Run: func(cmd *cobra.Command, args []string) {
start()
},
PersistentPreRun: func(cmd *cobra.Command, args []string) {
readConfigFile()
setupLogging()
},
}
rootCmd.PersistentFlags().String("log-level", "info", "one of debug, info, warn, error, or fatal")
rootCmd.PersistentFlags().String("log-format", "text", "specify output (text or json)")
rootCmd.PersistentFlags().String("consul", "http://localhost:8500", "Consul Api address")
rootCmd.PersistentFlags().String("marathon", "", "Marathon Api address")
rootCmd.PersistentFlags().String("marathon-user", "", "Marathon Api user")
rootCmd.PersistentFlags().String("marathon-password", "", "Marathon Api password")
rootCmd.PersistentFlags().Bool("marathon-no-verify-ssl", false, "Marathon SSL verification")
rootCmd.PersistentFlags().String("mesos", "", "Mesos Api address")
rootCmd.PersistentFlags().String("mesos-principal", "", "Mesos principal for framework authentication")
rootCmd.PersistentFlags().String("mesos-secret", "", "Mesos secret for framework authentication")
rootCmd.PersistentFlags().Bool("mesos-no-verify-ssl", false, "Mesos SSL verification")
rootCmd.PersistentFlags().String("listen", ":4001", "mantl-api listen address")
rootCmd.PersistentFlags().String("zookeeper", "", "Comma-delimited list of zookeeper servers")
rootCmd.PersistentFlags().Bool("force-sync", false, "Force a synchronization of all sources")
rootCmd.PersistentFlags().String("config-file", "", "The path to a configuration file")
for _, flags := range []*pflag.FlagSet{rootCmd.PersistentFlags()} {
err := viper.BindPFlags(flags)
if err != nil {
log.WithField("error", err).Fatal("could not bind flags")
}
}
viper.SetEnvPrefix("mantl_api")
viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))
viper.AutomaticEnv()
syncCommand := &cobra.Command{
Use: "sync",
Short: "Synchronize universe repositories",
Long: "Forces a synchronization of all configured sources",
Run: func(cmd *cobra.Command, args []string) {
sync(nil, true)
},
}
rootCmd.AddCommand(syncCommand)
rootCmd.Execute()
}
示例13: 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")
}
示例14: SetChaincodeLoggingLevel
// SetChaincodeLoggingLevel sets the chaincode logging level to the value
// of CORE_LOGGING_CHAINCODE set from core.yaml by chaincode_support.go
func SetChaincodeLoggingLevel() {
viper.SetEnvPrefix("CORE")
viper.AutomaticEnv()
replacer := strings.NewReplacer(".", "_")
viper.SetEnvKeyReplacer(replacer)
chaincodeLogLevelString := viper.GetString("logging.chaincode")
chaincodeLogLevel, err := LogLevel(chaincodeLogLevelString)
if err == nil {
SetLoggingLevel(chaincodeLogLevel)
} else {
chaincodeLogger.Infof("error with chaincode log level: %s level= %s\n", err, chaincodeLogLevelString)
}
}
示例15: main
func main() {
cnf := config.NewConfig()
cnf.AddFlags(pflag.CommandLine)
cnf.InitFlags()
viper.SetEnvPrefix("tinysyslog")
replacer := strings.NewReplacer("-", "_")
viper.SetEnvKeyReplacer(replacer)
viper.AutomaticEnv()
InitLogging()
server := NewServer()
server.Run()
}