app

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package app is the composition root: it builds the real adapters from the configuration, connects them to the use cases, and hands back the HTTP handler. It is the only place that knows every adapter; the layers it joins know only the ports between them.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Serve

func Serve(ctx context.Context, cfg config.Config, log *slog.Logger, ln net.Listener) error

Serve builds the application and serves it on ln until ctx is done, then shuts down: it ends the replies being written, lets requests finish, and releases the database. It is the program's whole run, so the program and the tests that stand in for it go through the same lines.

The caller opens ln first. Building runs the startup recovery, which marks every reply still streaming as interrupted; a second process that cannot get the port must fail before it can do that to the first one's live replies.

Types

type App

type App struct {
	// Handler serves every route, wrapped in the standard middleware.
	Handler http.Handler
	// EndStreams ends the replies being written, saving each as stopped. The
	// server calls it as it starts to shut down.
	EndStreams func()
	// contains filtered or unexported fields
}

App is the assembled application.

func Build

func Build(ctx context.Context, cfg config.Config, log *slog.Logger) (*App, error)

Build connects to the database, runs the startup tasks, and wires the application together. On error nothing is left open.

func (*App) Close

func (a *App) Close()

Close releases the database connections.

Jump to

Keyboard shortcuts

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