package config import ( "os" "strconv" "time" ) type Config struct { Server ServerConfig Postgres PostgresConfig Redis RedisConfig Log LogConfig Auth AuthConfig } type ServerConfig struct { Port string } type AuthConfig struct { JWTSecret string } type PostgresConfig struct { DSN string } type RedisConfig struct { Addr string Password string DB int } type LogConfig struct { BatchSize int FlushInterval time.Duration QueueCapacity 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), }, Log: LogConfig{ BatchSize: getEnvInt("EZ_LOG_BATCH_SIZE", 10), FlushInterval: getEnvDuration("EZ_LOG_FLUSH_MS", 1000), QueueCapacity: getEnvInt("EZ_LOG_QUEUE", 10000), }, Auth: AuthConfig{ JWTSecret: getEnv("EZ_JWT_SECRET", "change_me_in_production"), }, }, 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 } func getEnvDuration(key string, fallbackMs int) time.Duration { if value, ok := os.LookupEnv(key); ok { if i, err := strconv.Atoi(value); err == nil { return time.Duration(i) * time.Millisecond } } return time.Duration(fallbackMs) * time.Millisecond }