mirror of
https://github.com/spf13/viper
synced 2024-12-23 12:07:02 +00:00
Update for enabling cascading
This commit is contained in:
parent
24b9be4805
commit
10178ad847
1 changed files with 18 additions and 2 deletions
20
README.md
20
README.md
|
@ -1,4 +1,4 @@
|
||||||
viper [![Build Status](https://travis-ci.org/spf13/viper.svg)](https://travis-ci.org/spf13/viper)
|
viper <!--[![Build Status](https://travis-ci.org/spf13/viper.svg)](https://travis-ci.org/spf13/viper)-->
|
||||||
=====
|
=====
|
||||||
|
|
||||||
Go configuration with fangs
|
Go configuration with fangs
|
||||||
|
@ -69,13 +69,29 @@ Examples:
|
||||||
If you want to support a config file, Viper requires a minimal
|
If you want to support a config file, Viper requires a minimal
|
||||||
configuration so it knows where to look for the config file. Viper
|
configuration so it knows where to look for the config file. Viper
|
||||||
supports yaml, toml and json files. Viper can search multiple paths, but
|
supports yaml, toml and json files. Viper can search multiple paths, but
|
||||||
currently a single viper only supports a single config file.
|
currently a single viper only supports a single config file, unless cascading is enabled.
|
||||||
|
|
||||||
viper.SetConfigName("config") // name of config file (without extension)
|
viper.SetConfigName("config") // name of config file (without extension)
|
||||||
viper.AddConfigPath("/etc/appname/") // path to look for the config file in
|
viper.AddConfigPath("/etc/appname/") // path to look for the config file in
|
||||||
viper.AddConfigPath("$HOME/.appname") // call multiple times to add many search paths
|
viper.AddConfigPath("$HOME/.appname") // call multiple times to add many search paths
|
||||||
viper.ReadInConfig() // Find and read the config file
|
viper.ReadInConfig() // Find and read the config file
|
||||||
|
|
||||||
|
#### Enabling Cascading
|
||||||
|
|
||||||
|
By default Viper stops reading configuration once it encounters the first available configuration file.
|
||||||
|
That means each configuration file must contain all configuration values you need.
|
||||||
|
By enabling cascading you can create sparse configuration files. Configuration will cascade down in
|
||||||
|
the order that files are added by AddConfigPath. For more see viper_test's cascading tests.
|
||||||
|
|
||||||
|
Consider:
|
||||||
|
|
||||||
|
* \etc\myapp\myapp.json
|
||||||
|
* (%GOPATH)\src\myapp\myapp.json
|
||||||
|
|
||||||
|
You can check in a default myapp.json for development and only override certain kvps in production
|
||||||
|
|
||||||
|
viper.EnableCascading(true)
|
||||||
|
|
||||||
### Setting Overrides
|
### Setting Overrides
|
||||||
|
|
||||||
These could be from a command line flag, or from your own application logic.
|
These could be from a command line flag, or from your own application logic.
|
||||||
|
|
Loading…
Reference in a new issue