From 5ae3a072d1057b77d443b65ed0927998111ec766 Mon Sep 17 00:00:00 2001 From: lucperkins Date: Fri, 21 Jun 2019 18:43:31 -0700 Subject: [PATCH] Add documentation for no config file found Signed-off-by: lucperkins --- README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/README.md b/README.md index 5fdaa48..f4dc3bd 100644 --- a/README.md +++ b/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.