Options to set defaults for zero values only#325
Merged
caarlos0 merged 1 commit intocaarlos0:mainfrom Feb 21, 2025
Merged
Conversation
6bb7931 to
d7824e1
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #325 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 3 3
Lines 626 622 -4
=========================================
- Hits 626 622 -4 ☔ View full report in Codecov by Sentry. |
eacd4d3 to
4479add
Compare
4479add to
1d07485
Compare
caarlos0
reviewed
Feb 19, 2025
Owner
caarlos0
left a comment
There was a problem hiding this comment.
looks good, could you also add an example in example_test.go?
thanks!
1d07485 to
58aa16b
Compare
58aa16b to
e8b732f
Compare
Contributor
Author
I've added the example. Please check that it fits |
Owner
|
looks good, thanks @dnovikoff |
DmitriyMV
added a commit
to DmitriyMV/env
that referenced
this pull request
Jul 21, 2025
caarlos0#325 addressed the problem with `Parse` functions changing already set fields with default values, but created a problem when you can't change already set fields with non-default values. For example this works correctly: 1. Initialize struct with default values in tags and set struct fields explicitly. 2. Loading empty config/empty env using Parse. 3. Struct fields will remain the same if they were set during step 1. But this does not: 1. Initialize struct with default values in tags and set struct fields explicitly. 2. Loading non-empty config or non-empty env using Parse. 3. Struct fields will remain the same if they were set during step 1 but should get the non-empty values from the step 2. This PR fixes that.
DmitriyMV
added a commit
to DmitriyMV/env
that referenced
this pull request
Jul 21, 2025
caarlos0#325 addressed the problem with `Parse` functions changing already set fields with default values, but created a problem when you can't change already set fields with non-default values. For example this works correctly: 1. Initialize struct with default values in tags and set struct fields explicitly. 2. Loading empty config/empty env using Parse. 3. Struct fields will remain the same if they were set during step 1. But this does not: 1. Initialize struct with default values in tags and set struct fields explicitly. 2. Loading non-empty config or non-empty env using Parse. 3. Struct fields will remain the same if they were set during step 1 but should get the non-empty values from the step 2. This PR fixes that.
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.
I've encountered scenarious of loading config from file and then applying env vars.
Would be nice to ignore defaults for thouse values already set.