mirror of
https://github.com/spf13/viper
synced 2024-12-23 03:57:01 +00:00
Generic improvements
This commit is contained in:
parent
52836e66ad
commit
b6ced70067
1 changed files with 17 additions and 18 deletions
35
README.md
35
README.md
|
@ -20,10 +20,12 @@ Many Go projects are built using Viper including:
|
||||||
|
|
||||||
|
|
||||||
## Install
|
## Install
|
||||||
|
|
||||||
```console
|
```console
|
||||||
go get -u github.com/spf13/viper
|
go get github.com/spf13/viper
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
## What is Viper?
|
## What is Viper?
|
||||||
|
|
||||||
Viper is a complete configuration solution for Go applications including 12-Factor apps. It is designed
|
Viper is a complete configuration solution for Go applications including 12-Factor apps. It is designed
|
||||||
|
@ -39,8 +41,8 @@ and formats. It supports:
|
||||||
* reading from buffer
|
* reading from buffer
|
||||||
* setting explicit values
|
* setting explicit values
|
||||||
|
|
||||||
Viper can be thought of as a registry for all of your applications
|
Viper can be thought of as a registry for all of your applications configuration needs.
|
||||||
configuration needs.
|
|
||||||
|
|
||||||
## Why Viper?
|
## Why Viper?
|
||||||
|
|
||||||
|
@ -50,34 +52,31 @@ 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, envfile or Java properties formats.
|
1. Find, load, and unmarshal a configuration file in JSON, TOML, YAML, HCL, INI, 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 command line flags.
|
||||||
3. Provide a mechanism to set override values for options specified through
|
4. Provide an alias system to easily rename parameters without breaking existing code.
|
||||||
command line flags.
|
5. Make it easy to tell the difference between when a user has provided a command line or config file which is the same as the default.
|
||||||
4. Provide an alias system to easily rename parameters without breaking existing
|
|
||||||
code.
|
|
||||||
5. Make it easy to tell the difference between when a user has provided a
|
|
||||||
command line or config file which is the same as the default.
|
|
||||||
|
|
||||||
Viper uses the following precedence order. Each item takes precedence over the
|
Viper uses the following precedence order. Each item takes precedence over the item below it:
|
||||||
item below it:
|
|
||||||
|
|
||||||
* explicit call to Set
|
* explicit call to `Set`
|
||||||
* flag
|
* flag
|
||||||
* env
|
* env
|
||||||
* config
|
* config
|
||||||
* key/value store
|
* key/value store
|
||||||
* default
|
* default
|
||||||
|
|
||||||
Viper configuration keys are case insensitive.
|
**Important:** Viper configuration keys are case insensitive.
|
||||||
|
There are ongoing discussions about making that optional.
|
||||||
|
|
||||||
|
|
||||||
## Putting Values into Viper
|
## Putting Values into Viper
|
||||||
|
|
||||||
### Establishing Defaults
|
### Establishing Defaults
|
||||||
|
|
||||||
A good configuration system will support default values. A default value is not
|
A good configuration system will support default values. A default value is not
|
||||||
required for a key, but it’s useful in the event that a key hasn’t been set via
|
required for a key, but it’s useful in the event that a key hasn't been set via
|
||||||
config file, environment variable, remote configuration or flag.
|
config file, environment variable, remote configuration or flag.
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
|
@ -91,7 +90,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, envfile and Java Properties files. Viper can search multiple paths, but
|
Viper supports JSON, TOML, YAML, HCL, INI, 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.
|
||||||
|
|
Loading…
Reference in a new issue