Skip to content

feat!: set default if var is set but empty - #248

Merged
caarlos0 merged 1 commit into
mainfrom
245
Jan 21, 2023
Merged

caarlos0 merged 1 commit into
mainfrom
245

Conversation

@caarlos0

Copy link
Copy Markdown
Owner

BREAKING CHANGE: before this, env would set the default value for a variable only if the variable was never set, and would do nothing if it was set to an empty value. After this, it will set the default value if empty as well.

closes #245

@caarlos0 caarlos0 self-assigned this Jan 12, 2023
BREAKING CHANGE: before this, env would set the default value for a
variable only if the variable was never set, and would do nothing if it
was set to an empty value. After this, it will set the default value if
empty as well.

closes #245

Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
@codecov

codecov Bot commented Jan 12, 2023 •

Copy link
Copy Markdown

Codecov Report

Base: 100.00% // Head: 100.00% // No change to project coverage 👍

Coverage data is based on head (402cae8) compared to base (da848aa).
Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #248   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            2         2           
  Lines          356       358    +2     
=========================================
+ Hits           356       358    +2     
Impacted Files Coverage Δ
env.go 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

Comment thread env_test.go
@arvindh123

Copy link
Copy Markdown

It would great of there is some thing opposite to notEmpty tag, like allowEmpty tag. ?

Example :

type user struct {
     subscribe `env:"SUBSCRIBE,allowEmpty" envDefault:"yes"`
}

@caarlos0

Copy link
Copy Markdown
Owner Author

@arvindh123 tbh I think that would be confusing... rather keep it with fewer different behaviors...

@arvindh123

arvindh123 commented Jan 13, 2023 •

Copy link
Copy Markdown

@arvindh123 tbh I think that would be confusing... rather keep it with fewer different behaviors...
@caarlos0

It will be useful and It gives some more flexibility.
In similar kind of library , Viper there is option to treat empty environment variables as set
Quick reference link : https://github.com/spf13/viper#working-with-environment-variables

@dborovcanin

Copy link
Copy Markdown

Hello, @caarlos0. We plan on using this lib on the Mainflux project here. I agree with Arvindh's comment since it would provide some extra flexibility, but for our needs, this PR is sufficient as is. Any idea when it will be merged?

@caarlos0

Copy link
Copy Markdown
Owner Author

I still havent made my mind on this...

@drasko

drasko commented Jan 20, 2023

Copy link
Copy Markdown

@caarlos0 this one is blocking Mainflux development, so if it can't be merged by the end of this week we'll have to fork on Monday. I think it would be a pity to fragment the dev, so I hope there will be no need for fork.

@caarlos0
caarlos0 merged commit c687f95 into main Jan 21, 2023
@caarlos0
caarlos0 deleted the 245 branch January 21, 2023 01:00
@caarlos0

Copy link
Copy Markdown
Owner Author

Okay, I made up my mind.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Proposal: Adding Fallback to Default Value Option for Empty Environment Variables

4 participants