// Package config loads runtime configuration from environment variables. package config import ( "os" "strconv" "strings" ) // Config holds process-level settings. Anything the owner can change from the // web UI lives in the database instead (see store.Settings); the API-key // fields here only act as overrides when set. type Config struct { ListenAddr string DataDir string AdminUsername string AdminPassword string SecureCookies bool TrustProxy bool // Optional overrides for provider credentials. When set, the matching // setting is locked in the web UI. TMDBKey string TVDBKey string TVDBPin string IGDBClientID string IGDBClientSecret string } func Load() Config { port := env("CANON_PORT", "4242") return Config{ ListenAddr: env("CANON_LISTEN", ":"+port), DataDir: env("CANON_DATA_DIR", "./data"), AdminUsername: env("CANON_ADMIN_USERNAME", ""), AdminPassword: env("CANON_ADMIN_PASSWORD", ""), SecureCookies: envBool("CANON_SECURE_COOKIES", false), TrustProxy: envBool("CANON_TRUST_PROXY", false), TMDBKey: env("CANON_TMDB_API_KEY", ""), TVDBKey: env("CANON_TVDB_API_KEY", ""), TVDBPin: env("CANON_TVDB_PIN", ""), IGDBClientID: env("CANON_IGDB_CLIENT_ID", ""), IGDBClientSecret: env("CANON_IGDB_CLIENT_SECRET", ""), } } func env(key, def string) string { if v, ok := os.LookupEnv(key); ok && strings.TrimSpace(v) != "" { return strings.TrimSpace(v) } return def } func envBool(key string, def bool) bool { v, ok := os.LookupEnv(key) if !ok { return def } b, err := strconv.ParseBool(strings.TrimSpace(v)) if err != nil { return def } return b }