package config import ( "os" "path/filepath" "strings" ) // Config holds runtime settings for the RCS backend. type Config struct { Addr string DataDir string DBPath string ScreenshotDir string APIKey string ImgurClientID string // PublicBaseURL is the canonical public origin (e.g. https://rcs.example.com). PublicBaseURL string // TrustProxy honors X-Forwarded-Proto / X-Forwarded-Host when behind a reverse proxy. TrustProxy bool } // Load reads configuration from environment variables with sensible defaults. func Load() Config { dataDir := envOr("RCS_DATA_DIR", "data") dbPath := envOr("RCS_DB_PATH", filepath.Join(dataDir, "rcs.db")) screenshotDir := filepath.Join(dataDir, "screenshots") return Config{ Addr: envOr("RCS_ADDR", "127.0.0.1:8080"), DataDir: dataDir, DBPath: dbPath, ScreenshotDir: screenshotDir, APIKey: os.Getenv("RCS_API_KEY"), ImgurClientID: os.Getenv("IMGUR_CLIENT_ID"), PublicBaseURL: strings.TrimRight(os.Getenv("RCS_PUBLIC_BASE_URL"), "/"), TrustProxy: envTruthy("RCS_TRUST_PROXY"), } } func envOr(key, fallback string) string { if value := os.Getenv(key); value != "" { return value } return fallback } func envTruthy(key string) bool { switch strings.ToLower(strings.TrimSpace(os.Getenv(key))) { case "1", "true", "yes", "on": return true default: return false } }