Skip to content

feat(config): support environment variable default values#1577

Open
ndpvt-web wants to merge 1 commit intoTwiN:masterfrom
ndpvt-web:feat/env-var-default-values
Open

feat(config): support environment variable default values#1577
ndpvt-web wants to merge 1 commit intoTwiN:masterfrom
ndpvt-web:feat/env-var-default-values

Conversation

@ndpvt-web
Copy link

Summary

Adds support for default value fallback when using environment variables in gatus configuration using the standard shell syntax ${VAR:-default}.

Closes #1523

Changes

  • Added custom expandEnv() function in config/config.go that supports ${VAR:-default} syntax
  • If the environment variable is set and non-empty, its value is used
  • If the environment variable is unset or empty, the default value is used
  • Fully backward compatible with existing $VAR and ${VAR} syntax
  • Added comprehensive unit tests (15 test cases) in config/env_test.go

Example

endpoints:
  - name: My Endpoint
    url: "${API_URL:-https://api.example.com}"
    conditions:
      - "[STATUS] == ${EXPECTED_STATUS:-200}"

Test Plan

  • Unit tests for default value substitution
  • Tests for backward compatibility with existing syntax
  • Tests for edge cases (special chars, empty defaults, nested vars)
  • Manual testing with real config file

AI Disclosure

This PR was authored with assistance from an AI coding assistant (Claude). The implementation was developed transparently as part of an open-source contribution workflow. All code has been reviewed for correctness and follows the project's existing patterns.

Implements ${VAR:-default} syntax for environment variable expansion
in configuration files. If VAR is unset or empty, the default value
is used. This maintains backward compatibility with existing $VAR
and ${VAR} syntax.

Related to TwiN#1523

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions github-actions bot added the feature New feature or request label Mar 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Default value for environment variable in config

1 participant