feature/epic2-core-services #6
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user