Add dotenv documentation in README.md

This commit is contained in:
victor23d 2019-06-22 16:02:30 +00:00 committed by Márk Sági-Kazár
parent 3349bd9cc2
commit 2b4f7d3cde

View file

@ -27,7 +27,7 @@ to work within an application, and can handle all types of configuration needs
and formats. It supports: and formats. It supports:
* setting defaults * setting defaults
* reading from JSON, TOML, YAML, HCL, and Java properties config files * reading from JSON, TOML, YAML, HCL, envfile and Java properties config files
* live watching and re-reading of config files (optional) * live watching and re-reading of config files (optional)
* reading from environment variables * reading from environment variables
* reading from remote config systems (etcd or Consul), and watching changes * reading from remote config systems (etcd or Consul), and watching changes
@ -46,7 +46,7 @@ Viper is here to help with that.
Viper does the following for you: Viper does the following for you:
1. Find, load, and unmarshal a configuration file in JSON, TOML, YAML, HCL, or Java properties formats. 1. Find, load, and unmarshal a configuration file in JSON, TOML, YAML, HCL, envfile or Java properties formats.
2. Provide a mechanism to set default values for your different 2. Provide a mechanism to set default values for your different
configuration options. configuration options.
3. Provide a mechanism to set override values for options specified through 3. Provide a mechanism to set override values for options specified through
@ -87,7 +87,7 @@ viper.SetDefault("Taxonomies", map[string]string{"tag": "tags", "category": "cat
### Reading Config Files ### Reading Config Files
Viper requires minimal configuration so it knows where to look for config files. Viper requires minimal configuration so it knows where to look for config files.
Viper supports JSON, TOML, YAML, HCL, and Java Properties files. Viper can search multiple paths, but Viper supports JSON, TOML, YAML, HCL, envfile and Java Properties files. Viper can search multiple paths, but
currently a single Viper instance only supports a single configuration file. currently a single Viper instance only supports a single configuration file.
Viper does not default to any configuration search paths leaving defaults decision Viper does not default to any configuration search paths leaving defaults decision
to an application. to an application.
@ -372,7 +372,7 @@ package:
`import _ "github.com/spf13/viper/remote"` `import _ "github.com/spf13/viper/remote"`
Viper will read a config string (as JSON, TOML, YAML or HCL) retrieved from a path Viper will read a config string (as JSON, TOML, YAML, HCL or envfile) 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 or Consul. These values take precedence over
default values, but are overridden by configuration values retrieved from disk, default values, but are overridden by configuration values retrieved from disk,
flags, or environment variables. flags, or environment variables.
@ -407,7 +407,7 @@ how to use Consul.
#### etcd #### 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", "env", "dotenv"
err := viper.ReadRemoteConfig() err := viper.ReadRemoteConfig()
``` ```
@ -435,7 +435,7 @@ fmt.Println(viper.Get("hostname")) // myhostname.com
```go ```go
viper.AddSecureRemoteProvider("etcd","http://127.0.0.1:4001","/config/hugo.json","/etc/secrets/mykeyring.gpg") viper.AddSecureRemoteProvider("etcd","http://127.0.0.1:4001","/config/hugo.json","/etc/secrets/mykeyring.gpg")
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", "env", "dotenv"
err := viper.ReadRemoteConfig() err := viper.ReadRemoteConfig()
``` ```
@ -446,7 +446,7 @@ err := viper.ReadRemoteConfig()
var runtime_viper = viper.New() var runtime_viper = viper.New()
runtime_viper.AddRemoteProvider("etcd", "http://127.0.0.1:4001", "/config/hugo.yml") runtime_viper.AddRemoteProvider("etcd", "http://127.0.0.1:4001", "/config/hugo.yml")
runtime_viper.SetConfigType("yaml") // because there is no file extension in a stream of bytes, supported extensions are "json", "toml", "yaml", "yml", "properties", "props", "prop" runtime_viper.SetConfigType("yaml") // because there is no file extension in a stream of bytes, supported extensions are "json", "toml", "yaml", "yml", "properties", "props", "prop", "env", "dotenv"
// read from remote config the first time. // read from remote config the first time.
err := runtime_viper.ReadRemoteConfig() err := runtime_viper.ReadRemoteConfig()