Skip to content

Commit

Permalink
Generic improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
sagikazarmark committed Dec 6, 2019
1 parent 52836e6 commit b6ced70
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ Many Go projects are built using Viper including:


## Install

```console
go get -u github.com/spf13/viper
go get github.com/spf13/viper
```


## What is Viper?

Viper is a complete configuration solution for Go applications including 12-Factor apps. It is designed
Expand All @@ -39,8 +41,8 @@ and formats. It supports:
* reading from buffer
* setting explicit values

Viper can be thought of as a registry for all of your applications
configuration needs.
Viper can be thought of as a registry for all of your applications configuration needs.


## Why Viper?

Expand All @@ -50,34 +52,31 @@ Viper is here to help with that.

Viper does the following for you:

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
configuration options.
3. Provide a mechanism to set override values for options specified through
command line flags.
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.
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 configuration options.
3. Provide a mechanism to set override values for options specified through command line flags.
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
item below it:
Viper uses the following precedence order. Each item takes precedence over the item below it:

* explicit call to Set
* explicit call to `Set`
* flag
* env
* config
* key/value store
* 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

### Establishing Defaults

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 hasnt 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.

Examples:
Expand All @@ -91,7 +90,7 @@ viper.SetDefault("Taxonomies", map[string]string{"tag": "tags", "category": "cat
### Reading 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.
Viper does not default to any configuration search paths leaving defaults decision
to an application.
Expand Down

0 comments on commit b6ced70

Please sign in to comment.