From 3f5458e0d38d13f42f762b3a74aea52c24d94f48 Mon Sep 17 00:00:00 2001 From: Kiril Zvezdarov Date: Sat, 28 Mar 2015 13:36:55 -0400 Subject: [PATCH 1/2] Current working directory is added to the config search paths by default --- viper.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/viper.go b/viper.go index be41206..e9f7eb7 100644 --- a/viper.go +++ b/viper.go @@ -100,6 +100,13 @@ func New() *Viper { v.env = make(map[string]string) v.aliases = make(map[string]string) + wd, err := os.Getwd() + if err != nil { + jww.INFO.Println("Could not add cwd to search paths", err) + } else { + v.AddConfigPath(wd) + } + return v } From fe3c7838007b1946edfa67e3881b3a642adf090e Mon Sep 17 00:00:00 2001 From: Kiril Zvezdarov Date: Sat, 28 Mar 2015 13:43:38 -0400 Subject: [PATCH 2/2] Noted that ReadInConfig returns errors that can be handled --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e4268ba..5918fb7 100644 --- a/README.md +++ b/README.md @@ -74,7 +74,10 @@ currently a single viper only supports a single config file. viper.SetConfigName("config") // name of config file (without extension) 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.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 + panic(fmt.Errorf("Fatal error config file: %s \n", err)) + } ### Setting Overrides