docs: document that an empty env var falls back to envDefault - #428
Open
milanobrtlik wants to merge 1 commit into
Open
docs: document that an empty env var falls back to envDefault#428milanobrtlik wants to merge 1 commit into
milanobrtlik wants to merge 1 commit into
Conversation
If a field declares an envDefault, a variable set to an empty value is handled like an unset one. Neither required nor notEmpty guards against it: required is already satisfied by the default, and notEmpty only sees the value after the default was applied. Documents the existing behavior and the limitation behind it, and adds a runnable example. No behavior changes. Signed-off-by: Milan Obrtlík <milan@obrtlik.cz>
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.
envDefaultis documented as "sets the default value for the field", whichdoesn't mention that a variable set to an empty value gets the default too —
the behavior introduced in #248 and released in v7.0.0.
It is easy to miss, because neither
requirednornotEmptyguards against it:requiredis already satisfied by the default, andnotEmptyonly sees thevalue after the default was applied.
No behavior changes, just documentation of what already happens:
envDefaultbulletgo testand shows up onpkg.go.dev
Judging by #245 and #406, this keeps coming up.