Skip to content
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

Check that env is not empty #146

Open
koterin opened this issue Sep 27, 2023 · 5 comments
Open

Check that env is not empty #146

koterin opened this issue Sep 27, 2023 · 5 comments
Assignees

Comments

@koterin
Copy link

koterin commented Sep 27, 2023

We have a required flag that ensures that env is set. But it doesn't check if it's just listed or really set to any value.
It's crucial for most apps I'm working with and can help with throwing away ugly validators like this

...
if cfg.URL == "" {
    return errors.New("URL can't be empty")
}
...

This feature is also present in some other libs as notEmpty.

I suggest we add it here as well so providing a notEmpty flag would make a comparison of the env to its zero type value and throw parsing error as a result

@cristaloleg
Copy link
Member

Hi,

if it's just listed or really set to any value.

basically you're describing a case when FOO= (which is set but empty), am I right?

@koterin
Copy link
Author

koterin commented Sep 27, 2023

Hi,

if it's just listed or really set to any value.

basically you're describing a case when FOO= (which is set but empty), am I right?

Yeap, there are many cases when providing an empty value is fatal for the app in some further from initialization step. So we use those “ifs”, while having that flag in lib would be super comfy.

I may create a PR, if everyone likes the idea

@koterin koterin closed this as completed Sep 27, 2023
@koterin koterin reopened this Sep 27, 2023
@cristaloleg
Copy link
Member

I'm fine with it. Looks like the check should be added here (rough idea, haven't checked yet)

if field.isSet {

Feel free to submit a PR, thanks!

@cristaloleg
Copy link
Member

@koterin hey, can I assign it to you? (it's fine if you don't wanna take it, I will)

@koterin
Copy link
Author

koterin commented Oct 7, 2023

No, it's fine, I'll take it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants