You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm a bit confused by the documentation of the viper.SetConfigFile function. It says that
// SetConfigFile explicitly defines the path, name and extension of the config file.// Viper will use this and not check any of the config paths.funcSetConfigFile(instring) { v.SetConfigFile(in) }
At first glance, after reading "Viper will use this and not check any of the config paths", I would assume that if viper.SetConfigFile is used, then viper will ignore all the paths that were added via viper.AddConfigPath(). This seems to be true in the following example:
The output I got for the value of number that I set in my config2.json file, as expected. However, it seems that when I call viper.SetConfigName() after viper.SetConfigFile(), it doesn't use the file set via viper.SetConfigFile(). So in the example:
the output I get for the value of number is the one from config.yml, which is located in the current directory that is supposedly ignored.
The culprit seems to be viper.SetConfigName(), which removes the value of v.configFile. The other function viper.SetConfigFile() also writes that value.
Is this expected? From the documentation, I would've expected viper to read config2.json in both cases. Am I misinterpreting the documentation?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I'm a bit confused by the documentation of the
viper.SetConfigFile
function. It says thatAt first glance, after reading "Viper will use this and not check any of the config paths", I would assume that if
viper.SetConfigFile
is used, then viper will ignore all the paths that were added viaviper.AddConfigPath()
. This seems to be true in the following example:The output I got for the value of
number
that I set in myconfig2.json
file, as expected. However, it seems that when I callviper.SetConfigName()
afterviper.SetConfigFile()
, it doesn't use the file set viaviper.SetConfigFile()
. So in the example:the output I get for the value of
number
is the one fromconfig.yml
, which is located in the current directory that is supposedly ignored.The culprit seems to be
viper.SetConfigName()
, which removes the value ofv.configFile
. The other functionviper.SetConfigFile()
also writes that value.Is this expected? From the documentation, I would've expected viper to read
config2.json
in both cases. Am I misinterpreting the documentation?Beta Was this translation helpful? Give feedback.
All reactions