This commit is contained in:
lysu 2016-09-27 02:50:02 +00:00 committed by GitHub
commit 1cc54f348c
2 changed files with 12 additions and 5 deletions

View file

@ -12,6 +12,7 @@ import (
crypt "github.com/xordataexchange/crypt/config"
"io"
"os"
"strings"
)
type remoteConfigProvider struct{}
@ -54,15 +55,15 @@ func getConfigManager(rp viper.RemoteProvider) (crypt.ConfigManager, error) {
return nil, err
}
if rp.Provider() == "etcd" {
cm, err = crypt.NewEtcdConfigManager([]string{rp.Endpoint()}, kr)
cm, err = crypt.NewEtcdConfigManager(toMachines(rp.Endpoint()), kr)
} else {
cm, err = crypt.NewConsulConfigManager([]string{rp.Endpoint()}, kr)
cm, err = crypt.NewConsulConfigManager(toMachines(rp.Endpoint()), kr)
}
} else {
if rp.Provider() == "etcd" {
cm, err = crypt.NewStandardEtcdConfigManager([]string{rp.Endpoint()})
cm, err = crypt.NewStandardEtcdConfigManager(toMachines(rp.Endpoint()))
} else {
cm, err = crypt.NewStandardConsulConfigManager([]string{rp.Endpoint()})
cm, err = crypt.NewStandardConsulConfigManager(toMachines(rp.Endpoint()))
}
}
if err != nil {
@ -72,6 +73,11 @@ func getConfigManager(rp viper.RemoteProvider) (crypt.ConfigManager, error) {
}
func toMachines(endpoint string) []string {
machines := strings.Split(endpoint, ",")
return machines
}
func init() {
viper.RemoteConfig = &remoteConfigProvider{}
}

View file

@ -329,9 +329,10 @@ func (v *Viper) AddConfigPath(in string) {
}
// AddRemoteProvider adds a remote configuration source.
// Remote Providers are searched in the order they are added.
// Remote Providers are searched in the order they are added, and use first found provider.
// provider is a string value, "etcd" or "consul" are currently supported.
// endpoint is the url. etcd requires http://ip:port consul requires ip:port
// multiple addresses can configured in one url separated by commas
// path is the path in the k/v store to retrieve configuration
// To retrieve a config file called myapp.json from /configs/myapp.json
// you should set path to /configs and set config name (SetConfigName()) to