boot

package
v1.54.1 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package boot is the framework layer for this repo: every server implements the Service contract below, and pkg/boot/grpcserver and pkg/boot/httpserver build one from a service's handlers plus a declarative Config, so a service package never touches net.Listen, grpc.NewServer, or an interceptor chain directly. The one thing this package deliberately does not own is which services exist — each cmd/<name>/main.go supplies its own service's factory directly, since that mapping is different for every binary in the monorepo.

Index

Constants

View Source
const (
	ConfigKey   contextKey = "boot.config"
	IdentityKey contextKey = "boot.identity"
)
View Source
const (
	// PerServiceShutdownTimeout is what each service gets to drain, not a
	// budget split between them: services drain one at a time, so the process
	// can take this long per registered service.
	PerServiceShutdownTimeout = 15 * time.Second

	// PodTerminationGracePeriod is how long the kubelet waits after SIGTERM
	// before SIGKILL — hardcoded in fairway's deployment template, not this
	// repo, so verify it against a rendered Deployment rather than assuming
	// it. See .ai/components.md for the shutdown-timeout invariant this pins.
	PodTerminationGracePeriod = 60 * time.Second
)

Variables

This section is empty.

Functions

func ListenAndServe

func ListenAndServe(s Service) error

func MustInit

MustInit loads name's config section and returns a context carrying both it and name itself, so a service's handlers can identify themselves (e.g. in logging or telemetry) without name being threaded through every call.

func Run

func Run[T config.ServiceConfig](name string, factory ComponentsFactory[T])

Run is every binary's main(): initialize logging, Boot name's Components via factory, and run the resulting services until one exits or the process is signaled. Each cmd/<name>/main.go calls this directly with its own service's NewComponents — there is no registry to look name up in; a binary only ever boots the one service it was built for.

Types

type Components

type Components struct {
	GRPC *grpcserver.Registration
	HTTP *httpserver.Registration

	// DBPools names each of the service's database pools for automatic
	// pool-stats registration (see registerDBPools). Leave nil if unused.
	DBPools map[string]any
}

Components is what a service registers with the platform: its gRPC and/or HTTP surface, declaratively. Boot — not the service — decides which of them actually run, based on which addresses the service's own config sets. A service never constructs a *grpc.Server or *http.Server itself.

type ComponentsFactory

type ComponentsFactory[T config.ServiceConfig] func(ctx context.Context, cfg config.RuntimeConfig[T], m *metrics.Metrics, tracer *trace.Tracer) (Components, error)

ComponentsFactory builds a service's Components. m and tracer are always available — every service gets a metrics registry and, when GITLAB_TRACING is configured, a tracer — so a factory can register its own instruments (e.g. DB pool gauges) without owning telemetry's lifecycle.

type Service

type Service interface {
	Name() string
	Address() string
	Serve() error
	Shutdown(ctx context.Context) error
	Logger() *logrus.Entry
}

Service is the lifecycle contract every server in this repo implements, gRPC or HTTP. ServiceManager drives a []Service without knowing which transport backs any of them.

func Boot

func Boot[T config.ServiceConfig](ctx context.Context, name string, factory ComponentsFactory[T]) ([]Service, error)

Boot wires name into a running []Service; assemble decides which transports that includes.

type ServiceManager

type ServiceManager struct {
	// contains filtered or unexported fields
}

func NewServiceManager

func NewServiceManager(services ...Service) *ServiceManager

func (*ServiceManager) RunAll

func (m *ServiceManager) RunAll(ctx context.Context, cancel context.CancelCauseFunc) <-chan error

Directories

Path Synopsis
Package grpcserver builds the gRPC transport every service in this repo runs on: the interceptor chain, server reflection, the standard gRPC health service, and the Serve/Shutdown lifecycle pkg/boot.Service expects.
Package grpcserver builds the gRPC transport every service in this repo runs on: the interceptor chain, server reflection, the standard gRPC health service, and the Serve/Shutdown lifecycle pkg/boot.Service expects.
Package httpserver builds the HTTP transport every service in this repo runs on: CORS, access logging with correlation IDs, and the Serve/Shutdown lifecycle pkg/boot.Service expects.
Package httpserver builds the HTTP transport every service in this repo runs on: CORS, access logging with correlation IDs, and the Serve/Shutdown lifecycle pkg/boot.Service expects.

Jump to

Keyboard shortcuts

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