mirror of
https://github.com/spf13/viper
synced 2024-12-22 19:47:01 +00:00
Fixes #32
This commit is contained in:
parent
d027b73aef
commit
f927b1795c
1 changed files with 3 additions and 0 deletions
|
@ -73,11 +73,14 @@ viper.SetDefault("Taxonomies", map[string]string{"tag": "tags", "category": "cat
|
||||||
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 and YAML files. Viper can search multiple paths, but
|
Viper supports JSON, TOML and YAML 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
|
||||||
|
to an application.
|
||||||
|
|
||||||
```go
|
```go
|
||||||
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.AddConfigPath(".") // optionally look for config in the working directory
|
||||||
err := viper.ReadInConfig() // Find and read the config file
|
err := viper.ReadInConfig() // Find and read the config file
|
||||||
if err != nil { // Handle errors reading the config file
|
if err != nil { // Handle errors reading the config file
|
||||||
panic(fmt.Errorf("Fatal error config file: %s \n", err))
|
panic(fmt.Errorf("Fatal error config file: %s \n", err))
|
||||||
|
|
Loading…
Reference in a new issue