package config import ( "os" "strconv" ) type Config struct { Server ServerConfig Postgres PostgresConfig Redis RedisConfig } type ServerConfig struct { Port string } type PostgresConfig struct { DSN string } type RedisConfig struct { Addr string Password string DB int } func Load() (*Config, error) { return &Config{ Server: ServerConfig{ Port: getEnv("EZ_API_PORT", "8080"), }, Postgres: PostgresConfig{ DSN: getEnv("EZ_PG_DSN", "host=localhost user=postgres password=postgres dbname=ezapi port=5432 sslmode=disable"), }, Redis: RedisConfig{ Addr: getEnv("EZ_REDIS_ADDR", "localhost:6379"), Password: getEnv("EZ_REDIS_PASSWORD", ""), DB: getEnvInt("EZ_REDIS_DB", 0), }, }, nil } func getEnv(key, fallback string) string { if value, ok := os.LookupEnv(key); ok { return value } return fallback } func getEnvInt(key string, fallback int) int { if value, ok := os.LookupEnv(key); ok { if i, err := strconv.Atoi(value); err == nil { return i } } return fallback }