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

False value in json file #82

Open
mrazimi99 opened this issue Oct 12, 2021 · 3 comments
Open

False value in json file #82

mrazimi99 opened this issue Oct 12, 2021 · 3 comments

Comments

@mrazimi99
Copy link

mrazimi99 commented Oct 12, 2021

I'm trying to fill a required boolean field in the JSON file, and when the value is false, the following error raises:
field "boolVarName" is required but the value is not provided.
But when I change the value to true, everything goes well.

I think the issue is in the condition of line 316 of cleanenv.go, or the condition of line 329 where you check meta.isFieldValueZero().

@pkierski
Copy link

You can use pointer for required values with proper zero values.

type Config struct {
    FeatureEnabled *bool `env-required:"true" yaml:"enabled"`
}

@mrazimi99
Copy link
Author

You can use pointer for required values with proper zero values.

type Config struct {
    FeatureEnabled *bool `env-required:"true" yaml:"enabled"`
}

Thank you, it works.
Although I think the main problem still exists and can be solved.

@pkierski
Copy link

Some "no value" is required for detecting non-existent but required fields. Zero value is not so good idea, especially for bool. Pointer with nil as "no value" is quite good choice, but env-required:"true" should be forbidden for non-pointer types. So isFieldValueZero() should be transformed into isFieldValueNil() and should be check for *Type fields only.

Anther problem is lack of support pointer fields for environment vars: #81

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