Documentation
¶
Index ¶
- func Chain(h http.Handler, middlewares ...Middleware) http.Handler
- func RequestIDFromContext(ctx context.Context) string
- type Middleware
- func APIKeyAuth(validKeys []string, skipPaths []string, allowQueryAPIKey bool, ...) Middleware
- func CORS(allowedOrigins []string) Middleware
- func JWTAuth(cfg config.JWTConfig, skipPaths []string, logger *zap.Logger) Middleware
- func MetricsMiddleware(collector *metrics.Collector) Middleware
- func OTelTracing() Middleware
- func RateLimiter(ctx context.Context, rps float64, burst int, logger *zap.Logger) Middleware
- func Recovery(logger *zap.Logger) Middleware
- func RequestID() Middleware
- func RequestLogger(logger *zap.Logger) Middleware
- func SecurityHeaders() Middleware
- func TenantRateLimiter(ctx context.Context, rps float64, burst int, logger *zap.Logger) Middleware
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RequestIDFromContext ¶
RequestIDFromContext extracts the request ID from the context. Returns an empty string if no request ID is present.
Types ¶
type Middleware ¶
Middleware 类型定义
func APIKeyAuth ¶
func APIKeyAuth(validKeys []string, skipPaths []string, allowQueryAPIKey bool, logger *zap.Logger) Middleware
APIKeyAuth API Key 认证中间件
func JWTAuth ¶
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 ¶
RateLimiter 基于 IP 的请求限流中间件
func SecurityHeaders ¶
func SecurityHeaders() Middleware
SecurityHeaders adds common security response headers.
func TenantRateLimiter ¶
TenantRateLimiter applies rate limiting based on the tenant_id in the request context.
Click to show internal directories.
Click to hide internal directories.