Preflight Checklist

  • [X] I have searched the issue tracker for an issue that matches the one I want to file, without success.

Problem Description

Hi,

Some apps don't want the _ between prefix and variable name in environment variables name. For example, standard env prefix for openldap is LDAP as in LDAPNOINIT, LDAPRC, etc. The same goes for libpq with the PG prefix as in PGHOST, PGUSER, etc.

Proposed Solution

I suggest that viper v2 don't imposes the _ in the prefix and let the user set an explicit prefix. Migrating from v1 will just require to add a single underscore. That's seems fair. What do you think of this ?

Alternatives Considered

No response

Additional Information

This is somewhat related to case sensitivity. Env vars are case sensitive, think of http_proxy. viper should let user handle this. I understand viper can be opinionated. Still that would be great to bypass viper's opinion and keep the user in control.

Thanks for viper. It's awesome. And pflag too !

Regards, Étienne

Comment From: github-actions[bot]

👋 Thanks for reporting!

A maintainer will take a look at your issue 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! ❤️

Comment From: sagikazarmark

@bersace thank you for the suggestion!

I believe it should be possible to implement this feature in v1 by using a feature gate. We've introduced options a while ago, we could add a new one for this.

Would mind opening a PR?

On case sensitivity: I understand that in isolation it makes sense, but as soon as you try to merge env vars, case sensitivity just makes the problem infinitely more complex.

For example:

os.Setenv("http_proxy", "foo")
os.Setenv("http_PROXY", "bar")

viper.SetDefault("HTTP_PROXY", "baz")

viper.GetString("HTTP_proxy") // ????

There is a chance we can make it optional in certain cases, but due to the incredible complexity of Viper v1, it's certainly not going to happen over night.

Comment From: bersace

Cool, I'll try to implement this. Thanks for the feedback.

Comment From: github-actions[bot]

Issues with no activity for 30 days are marked stale and subject to being closed.