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:
- Read the configuration file, then let the environment override it.
- 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.
- 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.
- A reachable database whose setup_state row says complete closes setup permanently, whatever is on disk.
- 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 ¶
Types ¶
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.
Click to show internal directories.
Click to hide internal directories.