package config import ( "os" "strconv" ) // Config holds runtime configuration for the OpenGoods API server. // Values are read from environment variables with sensible defaults so the // server can boot in a local Docker Compose setup without extra configuration. type Config struct { Addr string DatabaseURL string RedisURL string AnonRateLimitPerMin int AnonTotalQuota int RegisteredRateLimitPerMin int RegisteredQuotaTotal int } // Load reads configuration from the environment. func Load() Config { return Config{ Addr: getenv("OPENGOODS_ADDR", ":8080"), DatabaseURL: getenv("OPENGOODS_DATABASE_URL", "postgres://opengoods:opengoods@localhost:5432/opengoods?sslmode=disable"), RedisURL: getenv("OPENGOODS_REDIS_URL", "redis://localhost:6379/0"), AnonRateLimitPerMin: getenvInt("OPENGOODS_ANON_RATE_LIMIT_PER_MIN", 60), AnonTotalQuota: getenvInt("OPENGOODS_ANON_TOTAL_QUOTA", 1000), RegisteredRateLimitPerMin: getenvInt("OPENGOODS_REGISTERED_RATE_LIMIT_PER_MIN", 300), RegisteredQuotaTotal: getenvInt("OPENGOODS_REGISTERED_QUOTA_TOTAL", 100000), } } func getenvInt(key string, fallback int) int { if v, ok := os.LookupEnv(key); ok && v != "" { if n, err := strconv.Atoi(v); err == nil && n > 0 { return n } } return fallback } func getenv(key, fallback string) string { if v, ok := os.LookupEnv(key); ok && v != "" { return v } return fallback }