mirror of
https://github.com/spf13/viper
synced 2024-11-04 20:27:02 +00:00
Add README.md for Consul remote provider (#489)
This commit is contained in:
parent
05116ad639
commit
8addaed22d
1 changed files with 21 additions and 0 deletions
21
README.md
21
README.md
|
@ -373,12 +373,33 @@ how to use Consul.
|
||||||
|
|
||||||
### Remote Key/Value Store Example - Unencrypted
|
### Remote Key/Value Store Example - Unencrypted
|
||||||
|
|
||||||
|
#### etcd
|
||||||
```go
|
```go
|
||||||
viper.AddRemoteProvider("etcd", "http://127.0.0.1:4001","/config/hugo.json")
|
viper.AddRemoteProvider("etcd", "http://127.0.0.1:4001","/config/hugo.json")
|
||||||
viper.SetConfigType("json") // because there is no file extension in a stream of bytes, supported extensions are "json", "toml", "yaml", "yml", "properties", "props", "prop"
|
viper.SetConfigType("json") // because there is no file extension in a stream of bytes, supported extensions are "json", "toml", "yaml", "yml", "properties", "props", "prop"
|
||||||
err := viper.ReadRemoteConfig()
|
err := viper.ReadRemoteConfig()
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### Consul
|
||||||
|
You need to set a key to Consul key/value storage with JSON value containing your desired config.
|
||||||
|
For example, create a Consul key/value store key `MY_CONSUL_KEY` with value:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"port": 8080,
|
||||||
|
"hostname": "myhostname.com"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
```go
|
||||||
|
viper.AddRemoteProvider("consul", "localhost:8500", "MY_CONSUL_KEY")
|
||||||
|
viper.SetConfigType("json") // Need to explicitly set this to json
|
||||||
|
err := viper.ReadRemoteConfig()
|
||||||
|
|
||||||
|
fmt.Println(viper.Get("port")) // 8080
|
||||||
|
fmt.Println(viper.Get("hostname")) // myhostname.com
|
||||||
|
```
|
||||||
|
|
||||||
### Remote Key/Value Store Example - Encrypted
|
### Remote Key/Value Store Example - Encrypted
|
||||||
|
|
||||||
```go
|
```go
|
||||||
|
|
Loading…
Reference in a new issue