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:
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.
Currently it is not possible to conditionally require environment variables based on another environment variable.
A feature like
envEnableIfwould be very helpful for cases where some configuration is only needed when a feature is enabled.For example, assume a server supports email sending:
Expected behavior:
EMAIL_ENABLED=false, SMTP variables are ignored.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.