mirror of
https://github.com/spf13/viper
synced 2024-12-22 19:47:01 +00:00
Add documentation for no config file found
Signed-off-by: lucperkins <lucperkins@gmail.com>
This commit is contained in:
parent
d34be8d9ee
commit
5ae3a072d1
1 changed files with 14 additions and 0 deletions
14
README.md
14
README.md
|
@ -107,6 +107,20 @@ if err != nil { // Handle errors reading the config file
|
|||
}
|
||||
```
|
||||
|
||||
You can handle the specific case where no config file is found like this:
|
||||
|
||||
```go
|
||||
if err := viper.ReadInConfig(); err != nil {
|
||||
if _, ok := err.(viper.ConfigFileNotFoundError); ok {
|
||||
// Config file not found; ignore error if desired
|
||||
} else {
|
||||
// Config file was found but another error was produced
|
||||
}
|
||||
}
|
||||
|
||||
// Config file found and successfully parsed
|
||||
```
|
||||
|
||||
### Writing Config Files
|
||||
|
||||
Reading from config files is useful, but at times you want to store all modifications made at run time.
|
||||
|
|
Loading…
Reference in a new issue