False value in json file
mrazimi99 opened this issue · comments
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()
.
You can use pointer for required values with proper zero values.
type Config struct {
FeatureEnabled *bool `env-required:"true" yaml:"enabled"`
}
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.
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