Documentation
¶
Overview ¶
Package middleware provides HTTP middleware for the Starmap API server. It includes logging, recovery, CORS, authentication, and rate limiting.
Index ¶
- func Auth(config AuthConfig, logger *zerolog.Logger) func(http.Handler) http.Handler
- func CORS(config CORSConfig) func(http.Handler) http.Handler
- func Chain(middlewares ...func(http.Handler) http.Handler) func(http.Handler) http.Handler
- func Logger(logger *zerolog.Logger) func(http.Handler) http.Handler
- func RateLimit(rl *RateLimiter) func(http.Handler) http.Handler
- func Recovery(logger *zerolog.Logger) func(http.Handler) http.Handler
- type AuthConfig
- type CORSConfig
- type RateLimiter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CORS ¶
func CORS(config CORSConfig) func(http.Handler) http.Handler
CORS middleware adds CORS headers to responses.
Types ¶
type AuthConfig ¶
type AuthConfig struct {
Enabled bool
APIKey string
HeaderName string
PublicPaths []string
BearerPrefix bool
}
AuthConfig holds authentication configuration.
func DefaultAuthConfig ¶
func DefaultAuthConfig() AuthConfig
DefaultAuthConfig returns default authentication configuration.
type CORSConfig ¶
type CORSConfig struct {
AllowedOrigins []string
AllowedMethods []string
AllowedHeaders []string
AllowAll bool
}
CORSConfig holds CORS configuration.
func DefaultCORSConfig ¶
func DefaultCORSConfig() CORSConfig
DefaultCORSConfig returns the default CORS configuration.
type RateLimiter ¶
type RateLimiter struct {
// contains filtered or unexported fields
}
RateLimiter implements token bucket rate limiting per IP address.
func NewRateLimiter ¶
func NewRateLimiter(limit int, logger *zerolog.Logger) *RateLimiter
NewRateLimiter creates a new rate limiter. limit is requests per minute per IP.
Click to show internal directories.
Click to hide internal directories.