config

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 9, 2026 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package config loads the server's startup settings, *arr-style: from environment variables and command-line flags. Only what the server needs before it can reach its database lives here. Everything else is managed in the app and stored in the database.

Index

Constants

View Source
const (
	EnvListen         = "PANELARR_LISTEN"
	EnvDatabaseURL    = "PANELARR_DB"
	EnvConfigDir      = "PANELARR_CONFIG"
	EnvDataDir        = "PANELARR_DATA"
	EnvBaseURL        = "PANELARR_BASE_URL"
	EnvLogFormat      = "PANELARR_LOG_FORMAT"
	EnvLogLevel       = "PANELARR_LOG_LEVEL"
	EnvMetricsEnabled = "PANELARR_METRICS_ENABLED"
	EnvMetricsListen  = "PANELARR_METRICS_LISTEN"
	EnvSecretKey      = "PANELARR_SECRET_KEY"
	EnvTrustedProxies = "PANELARR_TRUSTED_PROXIES"
	EnvMetaURL        = "PANELARR_META_URL"
	EnvMetaAPIKey     = "PANELARR_META_KEY" //nolint:gosec // a variable name, not a credential
	EnvWebDir         = "PANELARR_WEB_DIR"
)

Env names. Each setting can also be given as a flag.

View Source
const DefaultListen = ":8900"

DefaultListen is the server's port by convention.

View Source
const DefaultTrustedProxies = "127.0.0.0/8,::1/128,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16,fc00::/7"

DefaultTrustedProxies are loopback and private networks.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Listen is the address of the HTTP server. Default ":8900".
	Listen string
	// DatabaseURL is the PostgreSQL URL (or key=value DSN). Required.
	DatabaseURL string
	// ConfigDir holds the server's own files: the encryption key for stored
	// secrets, caches and logs. The image uses /config.
	ConfigDir string
	// DataDir is the default library location for downloads. The image
	// uses /data.
	DataDir string
	// BaseURL is the public URL the server is reached at, e.g.
	// "https://panelarr.example.com". Optional. It decides whether cookies
	// are marked Secure and how absolute links are built.
	BaseURL string
	// SecretKey encrypts stored secrets (service and plugin keys, storage
	// credentials): base64 of 32 bytes. Empty: a key file in ConfigDir,
	// generated on first use.
	SecretKey string
	// TrustedProxies are the networks whose X-Forwarded-For header is
	// believed when finding a client's address (for login limits and the
	// session list). Default: loopback and private networks, where reverse
	// proxies usually run.
	TrustedProxies []netip.Prefix
	// Meta, when its URL is set, is the metadata service connection; it
	// then can't be changed in the app. Empty: an admin connects it in the
	// first-run wizard.
	MetaURL    string
	MetaAPIKey string
	// WebDir serves the web app from a directory (a local build) instead of
	// the one embedded in the binary. For development.
	WebDir string
	// Log configures logging.
	Log Log
	// Metrics configures the Prometheus endpoint.
	Metrics Metrics
}

Config is the server's startup configuration.

func (Config) RequireDatabase

func (c Config) RequireDatabase() error

RequireDatabase reports a clear error when no database URL is set.

func (Config) SecureCookies

func (c Config) SecureCookies() bool

SecureCookies reports whether the public URL is https.

func (Config) Validate

func (c Config) Validate() error

Validate checks the settings that can be checked without side effects. A missing database URL is not an error here: commands that need the database check it themselves.

type Flags

type Flags struct {
	// contains filtered or unexported fields
}

Flags binds the settings to fs. Call Load after fs.Parse.

func (*Flags) Load

func (f *Flags) Load(getenv func(string) string) (Config, error)

Load builds the configuration from defaults, then the environment (read through getenv), then the flags, and validates it.

func (*Flags) Register

func (f *Flags) Register(fs *flag.FlagSet)

Register adds the flags to fs.

type Log

type Log struct {
	// Format is "json" (the default) or "text".
	Format string
	// Level is "debug", "info" (the default), "warn" or "error".
	Level string
}

Log configures structured logging.

type Metrics

type Metrics struct {
	Enabled bool
	// Listen is the metrics address, e.g. "127.0.0.1:9464". Empty: /metrics
	// on the API port, behind a metrics:read key.
	Listen string
}

Metrics configures Prometheus metrics. They are off by default. When on, they are served on their own address, or on the API port to callers whose API key has the metrics:read scope.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL