Hi guys, I'm having trouble with this too.
My code is as follows: v := viper.New() viper.SetConfigName("settings") viper.SetConfigType("json") viper.AddConfigPath(".") v.AutomaticEnv() err := v.ReadInConfig() if err != nil { logrus.Fatal("Fatal error config file: ", err) } However, I'm getting the error: Config File "config" Not Found in "[]". I've tried it with and without the SetConfigType but the error remains consistent. I've confirmed that the config file is in the same directory as the main.go file where this is being called too. Another odd thing is that the error message says Config File "config" not found, yet the config name is being set to "settings" (it had previously been called "config" but I changed it a while ago). Is there anything that you can see that I'm doing wrong? I'm running the app using the 'go run main.go' command too. My config is as follows: { "EMAIL_IDENTITY": "*****", "EMAIL_USERNAME": "*****", "EMAIL_PASSWORD": "*****", "EMAIL_HOST": "*****", "EMAIL_PORT": "*****", "EMAIL_RECIPIENT_NAME": "*****" } Thanks, John On Sunday, September 10, 2017 at 1:05:40 AM UTC+1, Tim Uckun wrote: > > I have this code > > v := viper.New() > v.SetConfigFile("settings.yaml") > v.AddConfigPath(".") > v.AddConfigPath("./settings") > v.AddConfigPath("./config") > err := v.ReadInConfig() > if err != nil { > panic(fmt.Errorf("Error when reading config: %v\n", err)) > } > > if as the instructions say I don't put the file extension in the > SetConfigFile it fails and says it doesn't recognize the type "". so I am > specifying the full name of the file. > > If I put this in the "." directory (same directory as my go file) it works > > if I put the file in the config or the settings or config directories it > doesn't work and gives me the following error > > > panic: Error when reading config: open settings.yaml: no such file or > directory > > How do I specify a relative path to viper? > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.