middleware

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2026 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Chain

func Chain(h http.Handler, middlewares ...Middleware) http.Handler

Chain 将多个中间件串联

func RequestIDFromContext

func RequestIDFromContext(ctx context.Context) string

RequestIDFromContext extracts the request ID from the context. Returns an empty string if no request ID is present.

Types

type Middleware

type Middleware func(http.Handler) http.Handler

Middleware 类型定义

func APIKeyAuth

func APIKeyAuth(validKeys []string, skipPaths []string, allowQueryAPIKey bool, logger *zap.Logger) Middleware

APIKeyAuth API Key 认证中间件

func CORS

func CORS(allowedOrigins []string) Middleware

CORS 跨域中间件

func JWTAuth

func JWTAuth(cfg config.JWTConfig, skipPaths []string, logger *zap.Logger) Middleware

JWTAuth validates JWT tokens from the Authorization: Bearer header and injects tenant_id, user_id, and roles into the request context.

func MetricsMiddleware

func MetricsMiddleware(collector *metrics.Collector) Middleware

MetricsMiddleware records HTTP request duration, status, and sizes via the provided metrics.Collector.

func OTelTracing

func OTelTracing() Middleware

OTelTracing creates a span for each HTTP request using the global OTel tracer.

func RateLimiter

func RateLimiter(ctx context.Context, rps float64, burst int, logger *zap.Logger) Middleware

RateLimiter 基于 IP 的请求限流中间件

func Recovery

func Recovery(logger *zap.Logger) Middleware

Recovery panic 恢复中间件

func RequestID

func RequestID() Middleware

RequestID adds a unique request ID to each request.

func RequestLogger

func RequestLogger(logger *zap.Logger) Middleware

RequestLogger 请求日志中间件

func SecurityHeaders

func SecurityHeaders() Middleware

SecurityHeaders adds common security response headers.

func TenantRateLimiter

func TenantRateLimiter(ctx context.Context, rps float64, burst int, logger *zap.Logger) Middleware

TenantRateLimiter applies rate limiting based on the tenant_id in the request context.

Jump to

Keyboard shortcuts

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