bootstrap

package
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2026 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Overview

Package bootstrap provides bootstrap utilities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HardenedServer

func HardenedServer(addr string, handler http.Handler, opts ...ServerOption) *http.Server

HardenedServer builds an http.Server with safe defaults and optional overrides.

func MountSystemEndpoints

func MountSystemEndpoints(r ports.HTTPRouter, se SystemEndpoints)

MountSystemEndpoints registers health, docs, version, and metrics endpoints.

func NewDefaultRouter

func NewDefaultRouter(log ports.Logger) (ports.HTTPRouter, error)

NewDefaultRouter constructs a router with a sensible default middleware stack.

func NewMigrator

func NewMigrator(dsn, table string, lockKey int64, allowDown bool, log ports.Logger, dirs []string, embedded []fs.FS) (ports.Migrator, error)

NewMigrator builds a migrator with either directories or embedded FS sources.

func NewMigratorWithContext

func NewMigratorWithContext(ctx context.Context, dsn, table string, lockKey int64, allowDown bool, log ports.Logger, dirs []string, embedded []fs.FS) (ports.Migrator, error)

NewMigratorWithContext builds a migrator with either directories or embedded FS sources.

func OpenAndPingDB

func OpenAndPingDB(ctx context.Context, dsn string, timeout time.Duration) (ports.DatabasePool, error)

OpenAndPingDB opens a DB pool and verifies connectivity with a short timeout.

func OpenPoolOrExit

func OpenPoolOrExit(ctx context.Context, dsn string, timeout time.Duration, log ports.Logger) ports.DatabasePool

OpenPoolOrExit opens a DB pool and terminates the process if it fails.

func RunDown

func RunDown(ctx context.Context, m ports.Migrator, dir string) error

RunDown runs migrations down with context and directory path.

func RunMigrationsOrExit

func RunMigrationsOrExit(ctx context.Context, cfg config.Config, log ports.Logger, embedded []fs.FS)

RunMigrationsOrExit runs startup migrations using config defaults or exits on failure.

func RunUp

func RunUp(ctx context.Context, m ports.Migrator, dir string) error

RunUp runs migrations up with context and directory path.

func StartServer

func StartServer(
	ctx context.Context,
	addr string,
	handler http.Handler,
	log ports.Logger,
) error

StartServer runs an HTTP server and performs graceful shutdown when the context is canceled.

func StartServerOrExit

func StartServerOrExit(
	ctx context.Context,
	addr string,
	handler http.Handler,
	log ports.Logger,
)

StartServerOrExit runs the HTTP server and exits the process when it fails.

func Status

func Status(ctx context.Context, m ports.Migrator, dir string) (string, error)

Status returns a text status of migrations.

func WithTimeout

func WithTimeout(parent context.Context, d time.Duration) (context.Context, context.CancelFunc)

WithTimeout derives a context with a default timeout for long-running migration ops.

Types

type Profile

type Profile struct {
	Middlewares   []func(http.Handler) http.Handler
	ServerOptions []ServerOption
}

Profile describes a middleware stack and server options.

func ProfileDev

func ProfileDev(log ports.Logger, opts ...ProfileOption) (Profile, error)

ProfileDev builds a developer-friendly profile with relaxed protections.

func ProfileStrictAPI

func ProfileStrictAPI(log ports.Logger, opts ...ProfileOption) (Profile, error)

ProfileStrictAPI builds a hardened API profile.

func (Profile) Apply

func (p Profile) Apply(r ports.HTTPRouter)

Apply attaches the profile middlewares to the router.

type ProfileOption

type ProfileOption func(*profileConfig)

ProfileOption customizes profile defaults.

func WithCORSOptions

func WithCORSOptions(opts ports.CORSOptions) ProfileOption

WithCORSOptions overrides CORS options.

func WithIdentityResolver

func WithIdentityResolver(resolver identity.Resolver) ProfileOption

WithIdentityResolver sets the trusted proxy resolver used by middleware.

func WithJSONStrict

func WithJSONStrict(strict bool) ProfileOption

WithJSONStrict toggles strict JSON parsing.

func WithMaxBodyBytes

func WithMaxBodyBytes(n int64) ProfileOption

WithMaxBodyBytes overrides max request body size.

func WithMetricsRecorder

func WithMetricsRecorder(rec metricsmw.MetricsRecorder) ProfileOption

WithMetricsRecorder sets the metrics recorder.

func WithOTelOptions

func WithOTelOptions(opts oteltrace.Options) ProfileOption

WithOTelOptions overrides OpenTelemetry middleware options.

func WithRateLimitDisabled

func WithRateLimitDisabled() ProfileOption

WithRateLimitDisabled disables rate limiting.

func WithRateLimitOptions

func WithRateLimitOptions(opts rateln.Options) ProfileOption

WithRateLimitOptions overrides rate limiting settings.

func WithRequestLogOptions

func WithRequestLogOptions(opts ...requestlog.Option) ProfileOption

WithRequestLogOptions appends request log options.

func WithRequestTimeout

func WithRequestTimeout(d time.Duration) ProfileOption

WithRequestTimeout overrides per-request timeout.

func WithSecureOptions

func WithSecureOptions(opts ...securemw.Option) ProfileOption

WithSecureOptions appends secure middleware options.

type ServerOption

type ServerOption func(*http.Server)

ServerOption configures an http.Server instance.

func WithIdleTimeout

func WithIdleTimeout(d time.Duration) ServerOption

WithIdleTimeout overrides IdleTimeout.

func WithMaxHeaderBytes

func WithMaxHeaderBytes(n int) ServerOption

WithMaxHeaderBytes overrides MaxHeaderBytes.

func WithReadHeaderTimeout

func WithReadHeaderTimeout(d time.Duration) ServerOption

WithReadHeaderTimeout overrides ReadHeaderTimeout.

func WithReadTimeout

func WithReadTimeout(d time.Duration) ServerOption

WithReadTimeout overrides ReadTimeout.

func WithWriteTimeout

func WithWriteTimeout(d time.Duration) ServerOption

WithWriteTimeout overrides WriteTimeout.

type SystemEndpoints

type SystemEndpoints struct {
	Health  *health.Handler
	Docs    *docs.Handler
	Version *version.Handler
	Pprof   http.Handler
	Metrics http.Handler
}

SystemEndpoints bundles handlers/config for mounting.

Jump to

Keyboard shortcuts

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