Files
canon/internal/config/config.go
T
cdnutterandClaude Opus 5.5 3923444b3b Rename project from TopDeck to Canon
- Module github.com/cdnutter/canon, binary/command cmd/canon, Docker
  image and compose project "canon"
- Environment variables now use the CANON_ prefix
- Default site title is "<Your name>'s Canon" (or "Canon" with no name);
  a Site title set in Settings still overrides it
- Existing topdeck.db (and WAL files) is renamed to canon.db on start
- README: upgrade notes, including moving the old compose volume

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-24 17:22:17 -07:00

65 lines
1.7 KiB
Go

// 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
}