bootstrap

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Overview

Package bootstrap wires a Fiber app — middleware, health, metrics, tracing, OpenAPI docs, i18n, and graceful shutdown — from a single Options struct.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type App

type App struct {
	*fiber.App
	// contains filtered or unexported fields
}

App wraps *fiber.App with graceful-shutdown cleanup hooks.

func New

func New(o Options) *App

New builds a Fiber app wired with recover, request-id/context, request logging, optional CORS, optional rate limiting, and optional health endpoints.

func (*App) Mount

func (a *App) Mount(mods ...Module) error

Mount wires each module into the app. For every module it, in order:

  1. runs Migrate(ctx) if the module implements Migrator AND the app was built with Options{AutoMigrate: true}; when AutoMigrate is false the schema is expected to be managed by external migration tooling,
  2. calls Register to mount routes,
  3. collects Checks() if the module implements HealthChecker (they then appear in /readyz).

It stops and returns a wrapped error on the first failure.

func (*App) Run

func (a *App) Run(addr string) error

Run starts the app and blocks until shutdown, then runs cleanup hooks.

type AsynqmonMount

type AsynqmonMount struct {
	Handler    http.Handler    // the UI handler, e.g. jobs.MonitoringHandler(opt, path)
	Path       string          // mount path; defaults to "/monitoring"
	Middleware []fiber.Handler // optional guards applied before the handler
}

AsynqmonMount configures mounting an external monitoring UI handler (e.g. the asynqmon dashboard) on the app. Kept generic so bootstrap need not import asynqmon.

type HealthChecker

type HealthChecker interface {
	Checks() []health.NamedCheck
}

HealthChecker is an optional Module capability: contribute readiness checks.

type Migrator

type Migrator interface {
	Migrate(ctx context.Context) error
}

Migrator is an optional Module capability: create/migrate tables on startup.

type Module

type Module interface {
	// Name identifies the module; it is used in error messages from Mount.
	Name() string
	// Register mounts the module's routes on r.
	Register(r fiber.Router) error
}

Module is a self-contained feature that registers its own routes. Implement the optional Migrator and HealthChecker interfaces to opt into startup migration and readiness reporting.

type Options

type Options struct {
	Logger             *logger.Logger
	RequestTimeout     time.Duration
	ShutdownTimeout    time.Duration
	DB                 *bun.DB
	EnableCORS         bool
	RateLimit          int
	RateLimitStorage   fiber.Storage
	SecurityHeaders    bool
	Compression        bool
	Idempotency        bool
	IdempotencyStorage fiber.Storage
	AutoMigrate        bool
	Metrics            bool
	Tracing            bool
	Cleanup            []func(context.Context) error
	Asynqmon           *AsynqmonMount
	HealthChecks       []health.NamedCheck
	FiberConfig        fiber.Config

	// OpenAPI, if non-nil, mounts the OpenAPI document at OpenAPISpecURL and a
	// Swagger UI at OpenAPIDocsURL.
	OpenAPI        *openapi.Spec
	OpenAPISpecURL string // default "/openapi.json"
	OpenAPIDocsURL string // default "/docs"

	// I18n, if set, mounts the locale-detection middleware so handlers can use
	// i18n.T / i18n.Locale.
	I18n *i18n.Bundle
}

Options configures the bootstrapped app. All fields are optional.

Jump to

Keyboard shortcuts

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