Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix config file search for full name with empty config type in viper_go1_15.go #1401

Conversation

rkobus
Copy link

@rkobus rkobus commented Jul 12, 2022

When config type is unset and filename provided with extension, viper fails to properly find that file.
According to the docs, providing config type when having full file name set is not required.

viper.SetConfigName("config") // name of config file (without extension)
viper.SetConfigType("yaml") // REQUIRED if the config file does not have the extension in the name
viper.AddConfigPath("/etc/appname/")   // path to look for the config file in

having configuration set like below:

vp = viper.New()
vp.AddConfigPath("./workdir/)
vp.SetConfigName("app.env")

causes viper to look for files app.env + "." + supportedExtension, eg. app.env.env
and to skip this part where config path and full file name are joined together.

if v.configType != "" {
		if b, _ := exists(v.fs, filepath.Join(in, v.configName)); b {
			return filepath.Join(in, v.configName)
		}
	}

code above that makes viper to look for file without adding supported extension at the end of config name is skipped because configType was intentionally unset (configType == ""). I think it should behave opposite - should be skipped when I intentionally set config type or config was found using built-in supported types.

When config type is unset and filename provided with extension viper failed to properly find that file. 
According to the docs, having set file name with extension is not required to provide config type.
@CLAassistant
Copy link

CLAassistant commented Jul 12, 2022

CLA assistant check
All committers have signed the CLA.

@github-actions
Copy link

👋 Thanks for contributing to Viper! You are awesome! 🎉

A maintainer will take a look at your pull request shortly. 👀

In the meantime: We are working on Viper v2 and we would love to hear your thoughts about what you like or don't like about Viper, so we can improve or fix those issues.

⏰ If you have a couple minutes, please take some time and share your thoughts: https://forms.gle/R6faU74qPRPAzchZ9

📣 If you've already given us your feedback, you can still help by spreading the news,
either by sharing the above link or telling people about this on Twitter:

https://twitter.com/sagikazarmark/status/1306904078967074816

Thank you! ❤️

Copy link
Collaborator

@sagikazarmark sagikazarmark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please provide a test that breaks without this change?

I'll have to review this patch (and past changes) carefully, because I suspect this change would break other (untested) features.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants