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

app

package
v0.23.0 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package app is the composition root: it wires configuration, the platform runtime, logging, caches, and API clients.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PrecheckConfig

func PrecheckConfig(explicitPath string) error

PrecheckConfig validates configuration existence without loading it: an explicitly named file must exist, and a legacy Ruby-DSL configuration is rejected. The CLI runs this on every command at parse time — Ruby loads the configuration eagerly at boot, so even `version` fails on a broken setup — while full parsing stays lazy in App construction.

Types

type App

type App struct {
	Config  config.Config
	Runtime *platform.Runtime
	Logger  *slog.Logger

	// PortalAPI returns the MOD Portal client, wired with the api cache and
	// retry as Client → CacheTransport → Retry (retry outermost, as in Ruby).
	PortalAPI func() (*api.MODPortalAPI, error)

	// Downloader returns the MOD file downloader, wired as Client → Retry
	// (no cache decorator: the downloader manages its own download-type
	// cache directly, matching Ruby's download_http_client).
	Downloader func() (*transfer.Downloader, error)

	// MODDownloadAPI returns the client for building authenticated MOD
	// download URLs. Credentials resolve lazily on first use, not here, so
	// commands that never actually download never require
	// FACTORIO_USERNAME/FACTORIO_TOKEN or player-data.json.
	MODDownloadAPI func() (*api.MODDownloadAPI, error)

	// ManagementAPI returns the client for API-key operations (upload,
	// edit, images), wired as Client → Retry with no cache. The API key
	// resolves lazily on first use, so commands only require
	// FACTORIO_API_KEY when a management operation actually runs.
	ManagementAPI func() (*api.MODManagementAPI, error)

	// GameDownloadAPI returns the client for the game download endpoints,
	// wired like PortalAPI (api cache + retry, as in Ruby's
	// api_http_client); the actual file download goes through Downloader.
	GameDownloadAPI func() (*api.GameDownloadAPI, error)
	// contains filtered or unexported fields
}

App holds the application-wide object graph. Expensive components are built lazily on first use, memoized via sync.OnceValues.

func New

func New(opts Options) (*App, error)

New builds the application.

func (*App) Caches

func (a *App) Caches() ([]NamedCache, error)

Caches returns the configured caches. The fixed order (download, api, info_json — the Ruby config definition order) keeps output deterministic; a map would randomize it per run. Instances are built fresh — cache state lives on disk, so they can coexist with the ones inside the API clients.

func (*App) Close

func (a *App) Close() error

Close releases resources (the log file).

func (*App) RequireGameStopped

func (a *App) RequireGameStopped() error

RequireGameStopped fails when Factorio is running; commands that modify game files call this first.

type NamedCache

type NamedCache struct {
	Name  string
	Cache cache.Cache
	TTL   *int64 // seconds; nil = unlimited
}

NamedCache pairs a configured cache with its name and TTL.

type Options

type Options struct {
	// ConfigPath is the explicitly requested configuration file (the
	// --config-path flag). When empty, FACTORIX_CONFIG is consulted, then
	// the default location (used only if present).
	ConfigPath string
	// LogLevel overrides the configured log_level when non-empty.
	LogLevel string
}

Options select the configuration and log level.

Jump to

Keyboard shortcuts

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