Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type APIKeyAuthenticator ¶
type APIKeyAuthenticator struct {
// contains filtered or unexported fields
}
APIKeyAuthenticator authenticates via a header-based API key
func NewAPIKeyAuthenticator ¶
func NewAPIKeyAuthenticator(header, key string, log *logger.Logger) *APIKeyAuthenticator
NewAPIKeyAuthenticator creates a new API key authenticator
func (*APIKeyAuthenticator) Authenticate ¶
func (a *APIKeyAuthenticator) Authenticate(r *http.Request) bool
Authenticate authenticates a request using an API key
type Authenticator ¶
Authenticator represents an authenticator
type BasicAuthenticator ¶
type BasicAuthenticator struct {
// contains filtered or unexported fields
}
BasicAuthenticator authenticates via HTTP Basic Auth
func NewBasicAuthenticator ¶
func NewBasicAuthenticator(username, password string, log *logger.Logger) *BasicAuthenticator
NewBasicAuthenticator creates a new basic authenticator
func (*BasicAuthenticator) Authenticate ¶
func (a *BasicAuthenticator) Authenticate(r *http.Request) bool
Authenticate authenticates a request using basic authentication
type JWTAuthenticator ¶
type JWTAuthenticator struct {
// contains filtered or unexported fields
}
JWTAuthenticator authenticates requests using HS256-signed JWT tokens.
func NewJWTAuthenticator ¶
func NewJWTAuthenticator(secret string, log *logger.Logger) *JWTAuthenticator
NewJWTAuthenticator creates a new JWT authenticator with an HMAC-SHA256 secret.
func (*JWTAuthenticator) Authenticate ¶
func (a *JWTAuthenticator) Authenticate(r *http.Request) bool
Authenticate validates the Bearer JWT in the Authorization header.
type Middleware ¶
Middleware represents a middleware function
func AuthMiddleware ¶
func AuthMiddleware(authenticator Authenticator, log *logger.Logger) Middleware
AuthMiddleware creates a middleware that authenticates requests
func Chain ¶
func Chain(middlewares ...Middleware) Middleware
Chain chains multiple middlewares together
func LoggingMiddleware ¶
func LoggingMiddleware(log *logger.Logger) Middleware
LoggingMiddleware creates a middleware that logs requests
func RateLimitMiddleware ¶
func RateLimitMiddleware(limiter *RateLimiter) Middleware
RateLimitMiddleware creates a middleware that limits the rate of requests per client IP.
func RequestIDMiddleware ¶
func RequestIDMiddleware() Middleware
RequestIDMiddleware ensures every request carries an X-Request-ID header. If the incoming request already has one it is forwarded as-is; otherwise a cryptographically random 16-character hex ID is generated and attached to both the inbound request (visible to the backend) and the response.
type RateLimiter ¶
type RateLimiter struct {
// contains filtered or unexported fields
}
RateLimiter implements a sliding-window rate limiter per client IP.
func NewRateLimiter ¶
NewRateLimiter creates a new rate limiter and starts a background cleanup goroutine.
func (*RateLimiter) Stop ¶
func (rl *RateLimiter) Stop()
Stop shuts down the background cleanup goroutine.