Skip to content

Feature Request: Conditional env validation (envEnableIf) #413

@arjunshajitech

Description

@arjunshajitech

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions