Feature Request: Conditional env validation (envEnableIf)
- Dominant language
- Go
- Stars
- 6.3k
- Forks
- 284
- Avg merge
- 1d 17h
- Merged PRs (30d)
- 1
Description
Currently it is not possible to conditionally require environment variables based on another environment variable.
A feature like `envEnableIf` would be very helpful for cases where some configuration is only needed when a feature is enabled.
For example, assume a server supports email sending:
```go
type Config struct {
EmailEnabled bool `env:"EMAIL_ENABLED"`
SMTPHost string `env:"SMTP_HOST" envEnableIf:"EMAIL_ENABLED"`
SMTPPort int `env:"SMTP_PORT" envEnableIf:"EMAIL_ENABLED"`
}
```
Expected behavior:
* If `EMAIL_ENABLED=false`, SMTP variables are ignored.
* If `EMAIL_ENABLED=true`, `SMTP_HOST`, `SMTP_PORT`, etc. should be required and validated.
This helps validate related configuration only when the feature is enabled, instead of requiring those variables all the time.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.