Go module
Install one adapter.
Go Core is installed automatically as a dependency.
go get github.com/pryznar/apirelio-gin@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"),
})
router := gin.New()
router.Use(authenticationMiddleware())
router.Use(gin.Recovery())
router.Use(apireliogin.Middleware(client, apireliogin.Options{}))Authentication should establish the account first. Keep gin.Recovery() outside Apirelio so recorded panics continue through Gin's normal recovery chain.
B2B context
Resolve stable business identifiers.
Resolvers run after the route handler. Return internal account and API-client identifiers; do not use email addresses, tokens or other personal data.
router.Use(apireliogin.Middleware(client, apireliogin.Options{
ResolveCustomer: func(ctx *gin.Context) *apirelio.Customer {
account, ok := ctx.Get("account")
if !ok {
return nil
}
return &apirelio.Customer{
ID: account.(*Account).ID,
Name: account.(*Account).Name,
Plan: account.(*Account).Plan,
}
},
ResolveApplication: func(ctx *gin.Context) *apirelio.Application {
return &apirelio.Application{ID: ctx.GetHeader("X-Client-ID")}
},
}))Scope
Keep only relevant routes.
apireliogin.Options{
IncludeRoutes: []string{"/api/**"},
ExcludeRoutes: []string{"/api/health", "/api/internal/**"},
APIVersionHeader: "X-API-Version",
}Patterns are exact paths or bounded prefixes ending 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.