Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Configuration

maniflex.Config is the single struct passed to maniflex.New. Every field has a sensible default; populate only the ones that differ from those defaults.

server := maniflex.New(maniflex.Config{
    Port:        8080,
    PathPrefix:  "/api",
    AutoMigrate: true,
})

Server

FieldDefaultPurpose
Port8080TCP port the HTTP server binds to
PathPrefix/apiURL prefix prepended to every generated model route and /openapi.json
ServiceName""service identifier added to logs, audit records, and the X-Service-Name response header
StaticDir<cwd>/staticfilesystem directory served as static files (relative paths resolve against cwd)
StaticPrefix/staticURL prefix the static directory is mounted under, at the router root
StaticDisabledfalseturn static file serving off entirely, even when the directory exists

PathPrefix does not affect /static, /files, or /health. Those are mounted at the router root. See Static Files for the static serving options.

Database

FieldDefaultPurpose
DBnilthe default DBAdapter. Usually set via server.SetDB(db) after MustRegister. Optional when every model has its own ModelConfig.Adapter — see Per-model adapter routing
AutoMigratetruerun schema migration on startup
DBWriteURL""DSN for the primary database (informational; populated by ConfigFromEnv)
DBReadURL""DSN for the read replica (informational)
QueryTimeout0 (unlimited)per-request deadline applied to all DB calls; exceeding it produces 504 TIMEOUT

See Database Backends for adapter construction.

File storage and encryption

FieldPurpose
FileStoragemaniflex.FileStorage implementation for mfx:"file" fields and the /files endpoints. Required if any model uses file uploads. See File Fields & Uploads.
FileMiddleware[]maniflex.MiddlewareFunc wrapping the standalone /files endpoints. Empty = no auth (backward-compatible default); production deployments should populate this with at least an auth middleware. See File Fields & Uploads.
KeyProvidermaniflex.KeyProvider for mfx:"encrypted" fields. Without one, encrypted fields refuse writes with 500 ENCRYPTION_NOT_CONFIGURED.

Logging

FieldDefaultPurpose
Loggerslog.Default()logger used for lifecycle, per-request, and adapter messages
PanicLoggerfalls back to Loggersink for the panic recoverer’s structured panic records
Tracezero (off)pipeline tracing — see below

Logger is used by ctx.Logger(), which adds request_id, trace_id, and service attributes per request. Route it to a JSON handler in production.

Pipeline tracing

Config.Trace enables verbose debug output of the request pipeline. All trace output is at DEBUG level through Logger, so the handler must accept DEBUG records to see anything.

Sub-flagEffect
Enabledshorthand for Steps + Timings + Aborts
Stepsenter/exit record per middleware
Timingsper-middleware elapsed time on exit records
Abortsthe source file:line of every ctx.Abort call
Bodieslog field names present in ctx.ParsedBody (opt-in; may expose sensitive field names)
Skipslog middleware skipped by ForModel/ForOperation filters
cfg.Trace = maniflex.PipelineTrace{Enabled: true, Skips: true}

Leave Bodies off in production.

Lifecycle

FieldDefaultPurpose
ShutdownTimeout30smaximum time Start() waits for in-flight requests to finish on SIGINT / SIGTERM before forcing the listener closed

See Graceful Shutdown.

Health probe

FieldDefaultPurpose
HealthCheckDBfalsewhen true, GET /health pings every distinct registered adapter (Config.DB plus any per-model overrides) and returns 503 on failure. Driver error messages are logged, not echoed in the response body, so DSN fragments can’t leak.
HealthTimeout3smaximum time the health handler waits for the DB ping

Set HealthTimeout shorter than your probe’s timeoutSeconds so the handler can return 503 cleanly before the probe times out.

Reading from environment

maniflex.ConfigFromEnv() populates a Config from a conventional set of environment variables (PORT, PATH_PREFIX, DB_WRITE_URL, DB_READ_URL, SERVICE_NAME, LOG_LEVEL, …). Use it for twelve-factor deployments, then override individual fields in code where needed.

cfg := maniflex.ConfigFromEnv()
cfg.AutoMigrate = false  // disable for production
server := maniflex.New(cfg)