-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
proposal: os: add function to return environment var with default value #35696
Comments
Which of the two do you mean? Either seems reasonable, and I don't think there's a clear winner. I think it's best to let the developer write another three lines and make it explicit and simple. If you want to avoid the extra typing, just set up an editor macro or copy-paste. |
I would personally go with
because this is technically how lookupenv works. If you look at the env.go they don't look too different from each other too much |
@timoheijne You missed or at least did not respond to the semantic difference that @mvdan was pointing out. Some programs will want to distinguish unset from empty; others will not. That's why both os.Getenv and os.LookupEnv exist. If you want to also set a default in one case or the other, it seems reasonable to ask the developer to write out which matters, explicitly.
Or, you know, write a function. :-) |
Given the semantic subtleties and how easy it is to write the function you want, this seems like a likely decline. Leaving open for a week for final comments. |
No change in consensus, so declining. |
Adding a very small QoL function to go giving the ability to return an environment variable with a possible fallback in one line
Since go doesn't support Overloading or Optional parameters (as far as I am aware)
I am proposing to add
the added benefit is this way it's also a non-breaking change
The text was updated successfully, but these errors were encountered: