Skip to content

Commit

Permalink
Add documentation for no config file found
Browse files Browse the repository at this point in the history
Signed-off-by: lucperkins <[email protected]>
  • Loading branch information
lucperkins authored and sagikazarmark committed Jul 13, 2019
1 parent d34be8d commit 5ae3a07
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 5ae3a07

Please sign in to comment.