diff --git a/remote/remote.go b/remote/remote.go index faaf3b3..1453134 100644 --- a/remote/remote.go +++ b/remote/remote.go @@ -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{} } diff --git a/viper.go b/viper.go index 0fbd051..362258c 100644 --- a/viper.go +++ b/viper.go @@ -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