Skip to content

Commit

Permalink
Merge remote-tracking branch 'jcftang-pr/master' into feaure/zookeeper
Browse files Browse the repository at this point in the history
  • Loading branch information
崔有省 committed Nov 16, 2018
2 parents ae103d7 + 7822eb6 commit c066298
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ and formats. It supports:
* reading from JSON, TOML, YAML, HCL, and Java properties config files
* live watching and re-reading of config files (optional)
* reading from environment variables
* reading from remote config systems (etcd or Consul), and watching changes
* reading from remote config systems (etcd, Consul or zookeeper), and watching changes
* reading from command line flags
* reading from buffer
* setting explicit values
Expand Down Expand Up @@ -347,7 +347,7 @@ package:
`import _ "github.com/spf13/viper/remote"`

Viper will read a config string (as JSON, TOML, YAML or HCL) retrieved from a path
in a Key/Value store such as etcd or Consul. These values take precedence over
in a Key/Value store such as etcd, Consul or zookeeper. These values take precedence over
default values, but are overridden by configuration values retrieved from disk,
flags, or environment variables.

Expand Down
4 changes: 4 additions & 0 deletions remote/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,16 @@ func getConfigManager(rp viper.RemoteProvider) (crypt.ConfigManager, error) {
}
if rp.Provider() == "etcd" {
cm, err = crypt.NewEtcdConfigManager([]string{rp.Endpoint()}, kr)
} else if rp.Provider() == "zookeeper" {
cm, err = crypt.NewZookeeperConfigManager([]string{rp.Endpoint()}, kr)
} else {
cm, err = crypt.NewConsulConfigManager([]string{rp.Endpoint()}, kr)
}
} else {
if rp.Provider() == "etcd" {
cm, err = crypt.NewStandardEtcdConfigManager([]string{rp.Endpoint()})
} else if rp.Provider() == "zookeeper" {
cm, err = crypt.NewStandardZookeeperConfigManager([]string{rp.Endpoint()})
} else {
cm, err = crypt.NewStandardConsulConfigManager([]string{rp.Endpoint()})
}
Expand Down
15 changes: 8 additions & 7 deletions viper.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,9 @@ func (str UnsupportedConfigError) Error() string {
return fmt.Sprintf("Unsupported Config Type %q", string(str))
}

// UnsupportedRemoteProviderError denotes encountering an unsupported remote
// provider. Currently only etcd and Consul are supported.
// Denotes encountering an unsupported remote
// provider. Currently only etcd, Consul, zookeeper are
// supported.
type UnsupportedRemoteProviderError string

// Error returns the formatted remote provider error.
Expand Down Expand Up @@ -228,7 +229,7 @@ func New() *Viper {
// can use it in their testing as well.
func Reset() {
v = New()
SupportedExts = []string{"json", "toml", "yaml", "yml", "properties", "props", "prop", "hcl"}
SupportedExts = []string{"json", "toml", "yaml", "yml", "hcl"}
SupportedRemoteProviders = []string{"etcd", "consul"}
}

Expand Down Expand Up @@ -269,8 +270,8 @@ type RemoteProvider interface {
// SupportedExts are universally supported extensions.
var SupportedExts = []string{"json", "toml", "yaml", "yml", "properties", "props", "prop", "hcl"}

// SupportedRemoteProviders are universally supported remote providers.
var SupportedRemoteProviders = []string{"etcd", "consul"}
// Universally supported remote providers.
var SupportedRemoteProviders []string = []string{"etcd", "consul"}

func OnConfigChange(run func(in fsnotify.Event)) { v.OnConfigChange(run) }
func (v *Viper) OnConfigChange(run func(in fsnotify.Event)) {
Expand Down Expand Up @@ -418,7 +419,7 @@ func (v *Viper) AddConfigPath(in string) {

// AddRemoteProvider adds a remote configuration source.
// Remote Providers are searched in the order they are added.
// provider is a string value, "etcd" or "consul" are currently supported.
// provider is a string value, "etcd", "consul" or "zookeeper" are currently supported.
// endpoint is the url. etcd requires http://ip:port consul requires ip:port
// path is the path in the k/v store to retrieve configuration
// To retrieve a config file called myapp.json from /configs/myapp.json
Expand Down Expand Up @@ -447,7 +448,7 @@ func (v *Viper) AddRemoteProvider(provider, endpoint, path string) error {

// AddSecureRemoteProvider adds a remote configuration source.
// Secure Remote Providers are searched in the order they are added.
// provider is a string value, "etcd" or "consul" are currently supported.
// provider is a string value, "etcd", "consul" or "zookeeper" are currently supported.
// endpoint is the url. etcd requires http://ip:port consul requires ip:port
// secretkeyring is the filepath to your openpgp secret keyring. e.g. /etc/secrets/myring.gpg
// path is the path in the k/v store to retrieve configuration
Expand Down

0 comments on commit c066298

Please sign in to comment.