Documentation
¶
Index ¶
- func Auth(cfg config.Config) gin.HandlerFunc
- func AuthWithAPIKeys(cfg config.Config, keySvc apikey.Service) gin.HandlerFunc
- func Logging() gin.HandlerFunc
- func OrgID(c *gin.Context) (string, bool)
- func RateLimit(limiter *ratelimit.Limiter) gin.HandlerFunc
- func Recover() gin.HandlerFunc
- func RequirePlan(billSvc billing.Service, minPlan string) gin.HandlerFunc
- func RequireRole(minRole string) gin.HandlerFunc
- func Tenant(orgSvc org.Service, ctxSvc userctx.Service) gin.HandlerFunc
- func UserID(c *gin.Context) (string, bool)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AuthWithAPIKeys ¶
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 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
Types ¶
This section is empty.