本文整理汇总了Golang中github.com/spf13/viper.SetEnvKeyReplacer函数的典型用法代码示例。如果您正苦于以下问题:Golang SetEnvKeyReplacer函数的具体用法?Golang SetEnvKeyReplacer怎么用?Golang SetEnvKeyReplacer使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SetEnvKeyReplacer函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
}
开发者ID:chop-dbhi,项目名称:scds,代码行数:35,代码来源:config.go
示例2: init
func init() {
viper.SetConfigType("yaml")
viper.AutomaticEnv()
envReplacer := strings.NewReplacer(".", "_")
viper.SetEnvKeyReplacer(envReplacer)
}
开发者ID:ricobl,项目名称:beat,代码行数:7,代码来源:config.go
示例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
}
开发者ID:butine,项目名称:research,代码行数:28,代码来源:chaincode.go
示例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
}
开发者ID:masterDev1985,项目名称:obc-peer,代码行数:34,代码来源:chaincode.go
示例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
}
开发者ID:Ritsyy,项目名称:almighty-core,代码行数:35,代码来源:configuration.go
示例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
}
开发者ID:RicHernandez2,项目名称:fabric,代码行数:35,代码来源:chaincode.go
示例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.....")
}
开发者ID:yoshiharay,项目名称:fabric,代码行数:58,代码来源:main.go
示例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)
}
开发者ID:crob1140,项目名称:CodeWiz,代码行数:9,代码来源:config.go
示例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()
}
开发者ID:gashcrumb,项目名称:gofabric8,代码行数:11,代码来源:root.go
示例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))
}
}
开发者ID:hyperledger,项目名称:fabric,代码行数:12,代码来源:test_util.go
示例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")
}
开发者ID:hellonicky,项目名称:notary,代码行数:12,代码来源:main.go
示例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()
}
开发者ID:nikolayvoronchikhin,项目名称:mantl-api,代码行数:52,代码来源:main.go
示例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")
}
开发者ID:klauern,项目名称:trackello,代码行数:50,代码来源:config.go
示例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)
}
}
开发者ID:yoshiharay,项目名称:fabric,代码行数:17,代码来源:chaincode.go
示例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()
}
开发者ID:admiralobvious,项目名称:tinysyslog,代码行数:15,代码来源:main.go
示例16: initConfig
// initConfig reads in config file and ENV variables if set.
func initConfig() {
if cfgFile != "" { // enable ability to specify config file via flag
viper.SetConfigFile(cfgFile)
}
viper.SetEnvPrefix("FISSILE")
viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))
viper.SetConfigName(".fissile") // name of config file (without extension)
viper.AddConfigPath("$HOME") // adding home directory as first search path
viper.AutomaticEnv() // read in environment variables that match
// If a config file is found, read it in.
if err := viper.ReadInConfig(); err == nil {
fmt.Println("Using config file:", viper.ConfigFileUsed())
}
}
开发者ID:hpcloud,项目名称:fissile,代码行数:18,代码来源:root.go
示例17: SetupTestConfig
// SetupTestConfig setup the config during test execution
func SetupTestConfig() {
flag.Parse()
// Now set the configuration file
viper.SetEnvPrefix("CORE")
viper.AutomaticEnv()
replacer := strings.NewReplacer(".", "_")
viper.SetEnvKeyReplacer(replacer)
viper.SetConfigName("core") // name of config file (without extension)
viper.AddConfigPath("../../peer/") // 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))
}
SetupTestLogging()
}
开发者ID:C0rWin,项目名称:fabric,代码行数:18,代码来源:config.go
示例18: SetupTestConfig
func SetupTestConfig() {
viper.AddConfigPath(".")
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
viper.AutomaticEnv()
viper.SetDefault("peer.ledger.test.loadYAML", true)
loadYAML := viper.GetBool("peer.ledger.test.loadYAML")
if loadYAML {
viper.SetConfigName("test")
err := viper.ReadInConfig()
if err != nil { // Handle errors reading the config file
panic(fmt.Errorf("Fatal error config file: %s \n", err))
}
}
var formatter = logging.MustStringFormatter(
`%{color}%{time:15:04:05.000} [%{module}] %{shortfunc} [%{shortfile}] -> %{level:.4s} %{id:03x}%{color:reset} %{message}`,
)
logging.SetFormatter(formatter)
}
开发者ID:Colearo,项目名称:fabric,代码行数:18,代码来源:ledger_suite_test.go
示例19: SetupTestConfig
// SetupTestConfig setup the config during test execution
func SetupTestConfig() {
runtime.GOMAXPROCS(runtime.NumCPU())
flag.Parse()
// Now set the configuration file
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
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))
}
SetupTestLogging()
}
开发者ID:butine,项目名称:research,代码行数:20,代码来源:config.go
示例20: 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")
if chaincodeLogLevelString == "" {
shimLogLevelDefault := logging.Level(shimLoggingLevel)
chaincodeLogger.Infof("Chaincode log level not provided; defaulting to: %s", shimLogLevelDefault)
} else {
chaincodeLogLevel, err := LogLevel(chaincodeLogLevelString)
if err == nil {
SetLoggingLevel(chaincodeLogLevel)
} else {
chaincodeLogger.Warningf("Error: %s for chaincode log level: %s", err, chaincodeLogLevelString)
}
}
}
开发者ID:hyperledger,项目名称:fabric,代码行数:22,代码来源:chaincode.go
注:本文中的github.com/spf13/viper.SetEnvKeyReplacer函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论