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
This commit is contained in:
2025-11-06 21:09:47 +01:00
parent cf4bf9505a
commit 54e1866997

View File

@@ -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
}