Skip to content

Instantly share code, notes, and snippets.

View anabeto93's full-sized avatar

Richard Anabeto Opoku anabeto93

View GitHub Profile
@anabeto93
anabeto93 / viper-env-expansion-solution.md
Created July 26, 2025 13:32
Viper Environment Variable Expansion Solution

Viper Environment Variable Expansion Solution

A working solution for Viper Issue #315 - Environment variable expansion in configuration files.

The Problem

While working with gofiber and using viper to load env variables from .env or .env.* (depending on environment such as .env.testing when testing), I noticed viper does not handle dynamic env variables properly. A simple googling of this problem showed me that since 2017, developers have needed Viper to support environment variable expansion in .env files. For example:

QUERY_DB_HOST=${QUERY_DB_HOST:-127.0.0.1}