Help us shape the future of Go! Take the 2026 Go Developer Survey

config

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Overview

Package config loads GoRun configuration.

Precedence (highest first): flags > environment > <DataDir>/gorun.toml > defaults. The data dir itself is resolved from --data / GORUN_DATA / default only.

Index

Constants

View Source
const MinSetupTokenLen = 16

MinSetupTokenLen is the shortest GORUN_SETUP_TOKEN accepted.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Coolify deployment integration: operator-only environment, never editable by a web request.
	UpdateURL, UpdateToken, UpdateResource string
	// Update configures the staged update lifecycle (trusted release source,
	// verification policy, health links). Operator-only, like the Coolify fields.
	Update UpdateConfig

	Addons          map[string]string // Optional addon modes: enabled, disabled or auto.
	TrustedProxies  []string          // GORUN_TRUSTED_PROXIES; empty trusts no forwarded headers
	CSPScriptSrc    []string          // GORUN_CSP_SCRIPT_SRC: extra public-page script sources (see PublicScriptSources)
	Env             string            // "dev" | "prod"
	DataDir         string            // GORUN_DATA, default ./data
	BaseURL         string            // GORUN_BASE_URL
	Addr            string            // GORUN_ADDR default 127.0.0.1:8080 (dev), :8080 (prod)
	SecretKey       []byte            // GORUN_SECRET_KEY (32 bytes after base64 decode) — required in prod, generated+persisted in dev
	AllowPrivateNet bool              // GORUN_ALLOW_PRIVATE_NET
	// MCPSameOwnerApproval (GORUN_MCP_SAME_OWNER_APPROVAL) lets an API key
	// approve MCP calls requested by another key of the same owner. Off by
	// default: approvals by key need a different person.
	MCPSameOwnerApproval bool
	// HSTSIncludeSubdomains (GORUN_HSTS_INCLUDE_SUBDOMAINS) and HSTSPreload
	// (GORUN_HSTS_PRELOAD) extend the HSTS header sent on https requests.
	// Off by default; preload requires includeSubDomains.
	HSTSIncludeSubdomains, HSTSPreload bool
	// Metrics (GORUN_METRICS) serves GET /metrics in Prometheus text format.
	// Off by default. MetricsToken (GORUN_METRICS_TOKEN) optional Bearer for scrapers.
	Metrics      bool
	MetricsToken string
	Stripe       struct{ SecretKey, WebhookSecret string } // STRIPE_SECRET_KEY, STRIPE_WEBHOOK_SECRET
	Theme        string                                    // GORUN_THEME default "default"
	SetupToken   string                                    // GORUN_SETUP_TOKEN: honored in every environment; required for prod setup (≥ 16 chars)
	S3           S3                                        // [s3] / GORUN_S3_*: media in an S3-compatible bucket
}

Config is the resolved runtime configuration.

func Load

func Load(args []string) (Config, error)

Load resolves the configuration from args (flags, without the program or subcommand name), the environment, the TOML file and defaults.

func LoadReadOnly

func LoadReadOnly(args []string) (Config, error)

LoadReadOnly validates existing configuration without generating a dev secret.

func (Config) DBPath

func (c Config) DBPath() string

DBPath is the SQLite database file inside DataDir.

func (Config) PublicScriptSources

func (c Config) PublicScriptSources() ([]string, error)

PublicScriptSources validates the operator's extra script-src entries for public pages (never the admin). The bundled themes need none; a custom theme that still loads a CDN or a self-hosted standard Alpine build lists what it needs, e.g. "https://cdn.jsdelivr.net 'unsafe-eval'". Entries are https origins or URL prefixes, or the keyword 'unsafe-eval'; anything broader (https:, *, 'unsafe-inline', data:) is refused.

func (Config) TrustedProxyNetworks

func (c Config) TrustedProxyNetworks() ([]netip.Prefix, error)

TrustedProxyNetworks validates operator-supplied networks, never inferred private ranges.

type S3

type S3 struct {
	Endpoint, Region, Bucket, AccessKey, SecretKey, PublicURL string
}

S3 is an S3-compatible bucket for media (empty = media on disk).

type UpdateConfig added in v0.15.0

type UpdateConfig struct {
	SourceURL   string   // GORUN_UPDATE_SOURCE_URL / [update] source_url: HTTPS release index (JSON)
	SourceToken string   // GORUN_UPDATE_SOURCE_TOKEN / [update] source_token: optional bearer for the index
	Artifact    string   // GORUN_UPDATE_ARTIFACT / [update] artifact: which artifact of a release to activate
	HealthLinks []string // GORUN_UPDATE_HEALTH_LINKS / [update] health_links: absolute URLs that must answer 2xx after activation
	// AllowDowngrade lets compatibility pass for a lower target version.
	AllowDowngrade bool // GORUN_UPDATE_ALLOW_DOWNGRADE / [update] allow_downgrade
	// AllowMissingDigest accepts releases whose source publishes no digest.
	AllowMissingDigest bool // GORUN_UPDATE_ALLOW_MISSING_DIGEST / [update] allow_missing_digest
	// ActivationTimeout bounds waiting for the provider or operator (default 15m).
	ActivationTimeout time.Duration // GORUN_UPDATE_ACTIVATION_TIMEOUT / [update] activation_timeout ("15m")
}

UpdateConfig is the operator configuration of staged core updates. An empty SourceURL disables requests; reads still work. Hosts and credentials never come from web requests.

Jump to

Keyboard shortcuts

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