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

app

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2026 License: GPL-3.0 Imports: 27 Imported by: 0

Documentation

Overview

Package app is the server's runtime: it decides which mode to start in, builds the listeners for that mode, and switches between them without the operator having to restart anything.

The startup decision

The database decides whether setup has run. Not the data directory — that is a cache of a connection string, and on a container it can live on a volume that does not survive a restart. The order is:

  1. Read the configuration file, then let the environment override it.
  2. If no connection string is known from either, there is nothing to ask, so the wizard runs and its first question is the connection string.
  3. If one is known, connect. A database that cannot be reached is a hard stop, not a wizard: a server that cannot reach its data has nothing to serve, and opening setup on an unreachable database is how an administrator account gets taken over.
  4. A reachable database whose setup_state row says complete closes setup permanently, whatever is on disk.
  5. A reachable database with no such row is a first run, or a run that was interrupted before its transaction committed. Either way the wizard runs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(ctx context.Context, opts Options) error

Run starts the server and blocks until ctx is cancelled or something fails. A clean shutdown returns nil.

Types

type Mode

type Mode string

Mode is which half of the server is running.

const (
	// ModeSetup serves the wizard and nothing else.
	ModeSetup Mode = "setup"
	// ModeNormal serves the admin panel, and in a later chunk the API.
	ModeNormal Mode = "normal"
)

The two modes. There is no third: a server is either being configured or serving.

type NotConfiguredError

type NotConfiguredError struct{ DataDir string }

NotConfiguredError is what Run returns when there is no way to reach a database and no way to ask for one. The command prints it and exits.

func (*NotConfiguredError) Error

func (e *NotConfiguredError) Error() string

Error implements error, and says what to do about it.

type Options

type Options struct {
	// DataDir is the data directory. Empty means beside the binary.
	DataDir string
	// Log is where structured lines go. nil means a discarding logger.
	Log *slog.Logger
	// Terminal is where the first-run banner and the setup token are printed.
	// It is deliberately not the logger: the token must never be in a log.
	Terminal io.Writer
	// Version is the build, for pages and for the setup record.
	Version string
	// Now is the clock, injectable for tests.
	Now func() time.Time
	// Listen and MetricsListen override the addresses in the configuration
	// file and the environment. Empty means use what is configured. They exist
	// for a supervisor that allocates ports, and for tests, which ask for
	// "127.0.0.1:0" and read back what they were given.
	Listen, MetricsListen string
	// OnListen, when set, is called each time the server begins listening,
	// with the mode it is in and the address its public listener bound. It is
	// how a test finds the port after asking for one, and how a supervisor
	// could learn the same thing.
	OnListen func(mode Mode, addr string)
}

Options is what Run needs from the command line and the environment.

Jump to

Keyboard shortcuts

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