From 54e186699768702b9f293789bd9ac6c8b2348f37 Mon Sep 17 00:00:00 2001 From: 0x1d Date: Thu, 6 Nov 2025 21:09:47 +0100 Subject: [PATCH] fix(config): Fix environment variable mapping for Docker - Add SetEnvKeyReplacer to convert underscores to dots - Explicitly bind DATABASE_DSN, REGISTRY_CONSUL_ADDRESS, REGISTRY_TYPE - Fixes database connection issues in Docker where services couldn't read DATABASE_DSN environment variable - Services in Docker can now connect to postgres:5432 instead of localhost --- internal/config/config.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/internal/config/config.go b/internal/config/config.go index 7d0b622..fed7764 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -3,6 +3,7 @@ package config import ( "fmt" + "strings" "time" "git.dcentral.systems/toolz/goplt/pkg/config" @@ -95,9 +96,13 @@ func LoadConfig(env string) (config.ConfigProvider, error) { // Enable environment variable support v.AutomaticEnv() - // Environment variables can be set in UPPER_SNAKE_CASE format - // and will automatically map to nested keys (e.g., SERVER_PORT -> server.port) - // Viper handles this automatically with AutomaticEnv() + // Set env key replacer to convert UPPER_SNAKE_CASE to nested keys + // e.g., DATABASE_DSN -> database.dsn, SERVER_PORT -> server.port + v.SetEnvKeyReplacer(strings.NewReplacer(".", "_")) + // Bind specific environment variables to config keys + v.BindEnv("database.dsn", "DATABASE_DSN") + v.BindEnv("registry.consul.address", "REGISTRY_CONSUL_ADDRESS") + v.BindEnv("registry.type", "REGISTRY_TYPE") return NewViperConfig(v), nil }