Go module
Install one adapter.
Go Core is installed automatically as a dependency.
go get github.com/pryznar/apirelio-fiber@v0.1.0Middleware
Register after authentication.
client := apirelio.New(apirelio.Config{
APIKey: os.Getenv("APIRELIO_API_KEY"),
Endpoint: "https://apirelio.com",
Service: "billing-api",
Environment: apirelio.EnvironmentProduction,
Release: os.Getenv("APP_RELEASE"),
})
app := fiber.New()
app.Use(authenticationMiddleware())
app.Use(recover.New())
app.Use(apireliofiber.Middleware(client, apireliofiber.Options{}))Authentication should establish the account first. Keep Fiber's recover middleware outside Apirelio so recorded panics continue through the normal recovery chain.
B2B context
Resolve stable business identifiers.
Resolvers run after downstream handlers. Return internal account and API-client identifiers; do not attach email addresses, tokens or other personal data.
app.Use(apireliofiber.Middleware(client, apireliofiber.Options{
ResolveCustomer: func(ctx *fiber.Ctx) *apirelio.Customer {
account, ok := ctx.Locals("account").(*Account)
if !ok {
return nil
}
return &apirelio.Customer{
ID: account.ID, Name: account.Name, Plan: account.Plan,
}
},
ResolveApplication: func(ctx *fiber.Ctx) *apirelio.Application {
return &apirelio.Application{ID: ctx.Get("X-Client-ID")}
},
}))Outcomes
Preserve errors, narrow the scope.
apireliofiber.Options{
IncludeRoutes: []string{"/api/**"},
ExcludeRoutes: []string{"/api/health", "/api/internal/**"},
ResolveErrorCode: func(ctx *fiber.Ctx, err error) string {
return stableErrorCode(err)
},
}Returned *fiber.Error values retain their HTTP status. Panics are recorded as 500 and re-thrown. Route patterns are exact or end in /**; exclusions always win.
Lifecycle
Flush within a deadline.
shutdownCtx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
if err := client.Shutdown(shutdownCtx); err != nil {
log.Printf("Apirelio shutdown: %v", err)
}The middleware only enqueues. Go Core batches outside the request path and retries transient delivery failures. Resolver, capture and transport failures never replace the customer response.
Request and response bodies, query strings, credentials, cookies, email addresses and client IP addresses are never included.