Files
canon/internal/config/config.go
T
cdnutterandClaude Opus 5.5 bcc5e69094 Listen on 0.0.0.0 by default and log LAN addresses
- New CANON_HOST (default 0.0.0.0; 127.0.0.1 keeps it on one machine)
- On start, log the http:// addresses other devices can use, skipping
  Docker/VM bridge interfaces
- docker-compose publishes 0.0.0.0:4242 explicitly
- README: opening Canon from other devices and firewall note

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

73 lines
2.0 KiB
Go

// Package config loads runtime configuration from environment variables.
package config
import (
"net"
"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
Host string
Port 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 {
// 0.0.0.0 accepts connections from other devices on the network, not
// just this machine. Use 127.0.0.1 to keep it local.
host := env("CANON_HOST", "0.0.0.0")
port := env("CANON_PORT", "4242")
return Config{
ListenAddr: env("CANON_LISTEN", net.JoinHostPort(host, port)),
Host: host,
Port: 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
}