env icon indicating copy to clipboard operation
env copied to clipboard

Add envDepends tag

Open dennis-dko opened this issue 2 years ago • 0 comments

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:

dennis-dko avatar Dec 23 '23 08:12 dennis-dko