From 2cf56962a6ad30fe6ed65cf0757644dfbe986585 Mon Sep 17 00:00:00 2001 From: casept Date: Sat, 16 Dec 2017 13:22:40 +0100 Subject: [PATCH 1/2] Document reading a specific config file in README --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index 64bf474..f5df776 100644 --- a/README.md +++ b/README.md @@ -103,6 +103,17 @@ if err != nil { // Handle errors reading the config file } ``` +Alternatively (or in addition), the path to a specific config file, +rather than to a directory containing config files, can be provided. + +```go +viper.SetConfigFile("$HOME/customconfig.toml") // explicitly add a specific config file +err := viper.ReadInConfig() // read the config file +if err != nil { // Handle errors reading the config file + panic(fmt.Errorf("Fatal error config file: %s \n", err)) +} +``` + ### Watching and re-reading config files Viper supports the ability to have your application live read a config file while running. From da44dc1a84e27984e075d6f5a8d96dd2032ef388 Mon Sep 17 00:00:00 2001 From: casept Date: Mon, 19 Nov 2018 08:27:41 +0000 Subject: [PATCH 2/2] reword --- README.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f5df776..c8a4c18 100644 --- a/README.md +++ b/README.md @@ -103,14 +103,13 @@ if err != nil { // Handle errors reading the config file } ``` -Alternatively (or in addition), the path to a specific config file, -rather than to a directory containing config files, can be provided. +Alternatively (or in addition), the path to a specific config file can be provided (instead of a directory). ```go viper.SetConfigFile("$HOME/customconfig.toml") // explicitly add a specific config file err := viper.ReadInConfig() // read 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 while loading config file: %s \n", err)) } ```