Repository navigation
docs: note that env cannot distinguish an empty variable from an unset one - #436
Open
milanobrtlik wants to merge 1 commit into
Open
milanobrtlik wants to merge 1 commit into
milanobrtlik wants to merge 1 commit into
Conversation
…t one Follow-up to caarlos0#432, which documented that a variable set to an empty value falls back to `envDefault`. Two things it left out: - What to do about it. With an `envDefault` in place the two cases are indistinguishable, so a field that needs to tell them apart has to leave the default out and rely on `notEmpty` or `os.LookupEnv`. - The `required`/`notEmpty` trap is stated in the README, but nothing checks it. The example now covers all three cases, so `go test` verifies the claim and pkg.go.dev shows it. The example's variables are renamed to `EMPTY_*`, since `FOO` is also used by other examples in this package.
Author
|
Note for whoever reviews this alongside #433: that PR adds The two don't conflict — this touches the Caveats block, #433 touches the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #432, which landed the caveat that was originally proposed in #428.
Two things are still missing:
What to do about it.
getOrreturns(defaultValue, exists=true, isDefault=true)for a variable that is set but empty:So with an
envDefaultin place, the two cases are indistinguishable. A fieldthat needs to tell them apart has to leave the default out and either use
notEmpty, which then rejects the empty value, or checkos.LookupEnvbeforeapplying a fallback. The Caveats note now says so.
The
required/notEmptytrap is asserted, but nothing checks it. TheREADME states it; no test covers it.
Example_parseEmptyEnvFallsBackToDefaultnow covers all three cases instead of the plain fallback only, so
go testverifies the claim and it shows up on pkg.go.dev.
The example's variables are renamed to
EMPTY_*, sinceFOOis also set byother examples in this package.
No behavior changes.