Viper AddConfigPath only finding file in current folder "."

Viewed 501

Have code that looks like

viper.AddConfigPath(".")
viper.AddConfigPath("$HOME/.config/myprogram")
viper.AddConfigPath("$HOME/configs")
viper.SetConfigFile("myprogram.yaml")

If I place myprogram.yaml in the current folder it works. However if I try putting it on either

$HOME/.config/myprogram
$HOME/configs

The yaml file is not found. Any ideas or suggestions?

1 Answers

From the viper docs:

SetConfigFile explicitly defines the path, name and extension of the config file. Viper will use this and not check any of the config paths.

So if you use SetConfigFile the paths will be ignored. Try (as per the example):

viper.SetConfigName("myprogram")
viper.SetConfigType("yaml")
viper.AddConfigPath(".")
viper.AddConfigPath("$HOME/configs")
viper.AddConfigPath("$HOME/.config/myprogram")
Related