Skip to main content

Overview

The env_vars section checks for the presence of environment variables and optionally validates their values against regex patterns. This ensures critical configuration values are set before running your application.

Configuration

Each environment variable check is defined by an EnvVarCheck struct (src/config.rs:31) with the following fields:
string
required
The name of the environment variable to check.
boolean
default:"true"
Whether the environment variable must be set. If true, validation fails when the variable is not defined.
string
A regex pattern to validate the variable’s value. If specified, the value must match this pattern.

Examples

Basic Presence Check

Check that an environment variable is set:

Optional Variables

Mark variables as optional when they have sensible defaults:

Pattern Validation

Validate that environment variable values match expected formats:

Real-World Examples

Pattern Syntax

The pattern field uses standard regex syntax. Here are common patterns:

Exact Values

Boolean Values

Numeric Ranges

URL Validation

Custom Formats

Remember to escape backslashes in YAML strings. Use \\ for a single backslash in regex patterns.

Default Behavior

From the struct definition in src/config.rs:31:
  • name: Required field, no default
  • required: Defaults to true
  • pattern: Defaults to None (no pattern validation)
When required: true, validation fails if:
  • The environment variable is not set
  • The variable is set but its value doesn’t match the pattern (if specified)
Use required: false with a pattern to validate optional variables only when they’re set. This allows developers to omit the variable entirely while ensuring correct values when provided.