middleware

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Auth

func Auth(cfg config.Config) gin.HandlerFunc

func AuthWithAPIKeys

func AuthWithAPIKeys(cfg config.Config, keySvc apikey.Service) gin.HandlerFunc

func Logging

func Logging() gin.HandlerFunc

Logging returns a middleware that logs each HTTP request with structured fields: method, path, status, latency, and client_ip. Log level is Info for 2xx/3xx, Warn for 4xx, Error for 5xx. trace_id and span_id are injected automatically by the otelHandler via context.

func OrgID

func OrgID(c *gin.Context) (string, bool)

func RateLimit

func RateLimit(limiter *ratelimit.Limiter) gin.HandlerFunc

RateLimit returns a middleware that limits requests using a token bucket algorithm. It applies rate limiting by client IP, and additionally by tenant (org_id) if available in the context.

Response headers:

  • X-RateLimit-Limit: max requests (burst)
  • X-RateLimit-Remaining: tokens left
  • Retry-After: seconds to wait (only on 429)

func Recover

func Recover() gin.HandlerFunc

Recover returns a middleware that recovers from panics, logs a structured error with stack trace, and returns a generic 500 JSON response. It replaces gin.Recovery() with structured logging via slog.

func RequirePlan

func RequirePlan(billSvc billing.Service, minPlan string) gin.HandlerFunc

RequirePlan checks that the org has an active subscription with the given plan or higher.

func RequireRole

func RequireRole(minRole string) gin.HandlerFunc

func Tenant

func Tenant(orgSvc org.Service, ctxSvc userctx.Service) gin.HandlerFunc

func UserID

func UserID(c *gin.Context) (string, bool)

Types

This section is empty.

Jump to

Keyboard shortcuts

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