config

package
v0.0.0-...-97f3efd Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2026 License: BSD-2-Clause Imports: 9 Imported by: 0

Documentation

Overview

Package config loads and validates server configuration from a TOML file (subset parser in toml.go) with CLI-flag overrides applied on top. Precedence: defaults < config file < flags.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadFile

func LoadFile(path string, cfg *Config) error

LoadFile parses the TOML file at path into cfg (which should start as Default()). Unknown sections or keys are errors.

Types

type App

type App struct {
	ID             string
	AllowedOrigins []string
	MaxPlayersMax  int
	AllowTurn      bool
}

type Config

type Config struct {
	Server   Server
	Security Security
	Turn     Turn
	Rooms    Rooms
	Apps     []App
}

Config is the fully-resolved server configuration.

func Default

func Default() Config

Default returns the built-in defaults matching the implementation guide.

func (*Config) AppByID

func (c *Config) AppByID(id string) *App

AppByID returns the app policy for id, or nil.

func (*Config) OriginAllowed

func (c *Config) OriginAllowed(origin string) bool

OriginAllowed reports whether origin (scheme://host[:port]) is in the global allowlist. Matching is exact and case-insensitive on scheme/host per RFC 6454 serialization conventions.

func (*Config) OriginAllowedForApp

func (c *Config) OriginAllowedForApp(origin string, app *App) bool

OriginAllowedForApp reports whether origin is acceptable for the app: either globally allowlisted or on the app's own allowlist.

func (*Config) Validate

func (c *Config) Validate() error

Validate checks cross-field invariants and loads the TURN secret.

type Rooms

type Rooms struct {
	EmptyTTL       time.Duration
	MaxTTL         time.Duration
	MaxRooms       int
	MaxPlayersHard int
	ClaimAfter     time.Duration
	GCInterval     time.Duration
}

type Security

type Security struct {
	AllowedOrigins    []string
	MaxWSMessageBytes int64
	// AllowNoOrigin permits WebSocket connections without an Origin
	// header (native clients). Off by default.
	AllowNoOrigin bool
}

type Server

type Server struct {
	PublicURL      string
	ListenHTTP     string // e.g. "127.0.0.1:8787"; empty disables
	ListenHTTPS    string // e.g. ":4443"; empty disables
	Cert           string
	Key            string
	BehindProxy    bool
	TrustedProxies []string
	LogLevel       string // debug|info|warn|error
}

type Turn

type Turn struct {
	Enabled          bool
	Realm            string
	SharedSecretFile string
	TTL              time.Duration
	URLs             []string

	// Secret is loaded from SharedSecretFile at startup.
	Secret []byte
}

Jump to

Keyboard shortcuts

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