env
env copied to clipboard
Add envDepends tag
Hello,
In my case I want to use the "notEmpty" tag for a field like:
type foobar struct{
IsEnabled bool `env:"IS_ENABLED" envDefault:"true"`
Name string `env:"NAME,notEmpty"`
}
but the "NAME" should depends on if "IS_ENABLED" is set. My idea is to add a new tag envDepends like the same syntax as envDefault. In the envDepends tag you can define the needed env field(s).
The new struct will be shown like:
type foobar struct{
IsEnabled bool `env:"IS_ENABLED envDefault:"true"`
Name string `env:"NAME" envDepends:"IS_ENABLED, ...."`
}
The envDepends combine "required" and "notEmpty" tag to ensure that all needed fields have values (by environment or default tag) if you use the field "IS_ENABLED" in my example above.
What do you think about it? :blush: