Documentation
¶
Index ¶
- Constants
- func BasicAuthMiddleware[T any](cfg BasicAuthConfig) aether.HandlerFunc[T]
- func CORSMiddleware[T any](cfg CORSConfig) aether.HandlerFunc[T]
- func CSRFMiddleware[T any](cfg CSRFConfig) aether.HandlerFunc[T]
- func ExternalRecoveryMiddleware[T any](customHandler func(c *aether.Context[T], err any)) aether.HandlerFunc[T]
- func GetClaims[T any](c *aether.Context[T]) jwt.Claims
- func GetMapClaims[T any](c *aether.Context[T]) jwt.MapClaims
- func GzipMiddleware[T any]() aether.HandlerFunc[T]
- func HelmetMiddleware[T any](cfg HelmetConfig) aether.HandlerFunc[T]
- func JWTMiddleware[T any](cfg JWTConfig) aether.HandlerFunc[T]
- func LoggerMiddleware[T any]() aether.HandlerFunc[T]
- func RateLimiterMiddleware[T any](cfg RateLimiterConfig) aether.HandlerFunc[T]
- func RequestIDMiddleware[T any]() aether.HandlerFunc[T]
- type BasicAuthConfig
- type CORSConfig
- type CSRFConfig
- type HelmetConfig
- type JWTConfig
- type JWTValidator
- type MemStoreItem
- type MemoryRateLimiterStore
- type RateLimiterConfig
- type RateLimiterStore
Constants ¶
const ClaimsContextKey contextKey = "aether_jwt_claims"
ClaimsContextKey is the context key for storing JWT claims.
Variables ¶
This section is empty.
Functions ¶
func BasicAuthMiddleware ¶
func BasicAuthMiddleware[T any](cfg BasicAuthConfig) aether.HandlerFunc[T]
BasicAuthMiddleware provides HTTP Basic Authentication.
func CORSMiddleware ¶
func CORSMiddleware[T any](cfg CORSConfig) aether.HandlerFunc[T]
CORSMiddleware handles Cross-Origin Resource Sharing headers.
func CSRFMiddleware ¶
func CSRFMiddleware[T any](cfg CSRFConfig) aether.HandlerFunc[T]
CSRFMiddleware provides CSRF token generation and validation.
func ExternalRecoveryMiddleware ¶
func ExternalRecoveryMiddleware[T any](customHandler func(c *aether.Context[T], err any)) aether.HandlerFunc[T]
ExternalRecoveryMiddleware recovers from panics with custom error handling.
func GetMapClaims ¶
GetMapClaims retrieves JWT claims as a MapClaims from the request context.
func GzipMiddleware ¶
func GzipMiddleware[T any]() aether.HandlerFunc[T]
GzipMiddleware compresses responses using gzip encoding.
func HelmetMiddleware ¶
func HelmetMiddleware[T any](cfg HelmetConfig) aether.HandlerFunc[T]
HelmetMiddleware adds security HTTP headers to responses.
func JWTMiddleware ¶
func JWTMiddleware[T any](cfg JWTConfig) aether.HandlerFunc[T]
JWTMiddleware provides JWT token validation and authentication.
func LoggerMiddleware ¶
func LoggerMiddleware[T any]() aether.HandlerFunc[T]
LoggerMiddleware logs HTTP requests with method, path, status, and duration.
func RateLimiterMiddleware ¶
func RateLimiterMiddleware[T any](cfg RateLimiterConfig) aether.HandlerFunc[T]
RateLimiterMiddleware limits request rate based on configuration.
func RequestIDMiddleware ¶
func RequestIDMiddleware[T any]() aether.HandlerFunc[T]
RequestIDMiddleware adds a unique request ID to each request.
Types ¶
type BasicAuthConfig ¶
type BasicAuthConfig struct {
Users map[string]string
Validate func(user, password string) bool
Realm string
}
BasicAuthConfig holds configuration for Basic Authentication middleware.
type CORSConfig ¶
type CORSConfig struct {
AllowOrigins []string
AllowMethods []string
AllowHeaders []string
ExposeHeaders []string
AllowCredentials bool
MaxAge int
}
CORSConfig holds configuration for Cross-Origin Resource Sharing middleware.
type CSRFConfig ¶
type CSRFConfig struct {
TokenLength int
CookieName string
HeaderName string
CookiePath string
Secure bool
HttpOnly bool
SameSite http.SameSite
SkipFunc func(req *http.Request) bool
}
CSRFConfig holds configuration for CSRF protection middleware.
type HelmetConfig ¶
type HelmetConfig struct {
XSSProtection string
ContentTypeNosniff string
XFrameOptions string
HSTSMaxAge int
HSTSExcludeSubdomains bool
ContentSecurityPolicy string
ReferrerPolicy string
}
HelmetConfig holds configuration for security headers middleware.
func DefaultHelmetConfig ¶
func DefaultHelmetConfig() HelmetConfig
DefaultHelmetConfig returns the default security headers configuration.
type JWTConfig ¶
type JWTConfig struct {
Secret []byte
SigningMethod jwt.SigningMethod
ClaimsFunc func() jwt.Claims
Validator JWTValidator
TokenLookup string
ErrorHandler func(c *aether.Context[any], err error)
}
JWTConfig holds configuration for JWT authentication middleware.
type JWTValidator ¶
JWTValidator defines the interface for JWT token validation.
type MemStoreItem ¶
type MemStoreItem struct {
Count int
ExpiresAt time.Time
// contains filtered or unexported fields
}
MemStoreItem represents a rate limiter entry with count and expiration.
type MemoryRateLimiterStore ¶
type MemoryRateLimiterStore struct {
// contains filtered or unexported fields
}
MemoryRateLimiterStore is an in-memory implementation of RateLimiterStore.
func NewMemoryRateLimiterStore ¶
func NewMemoryRateLimiterStore() *MemoryRateLimiterStore
NewMemoryRateLimiterStore creates a new in-memory rate limiter store.
type RateLimiterConfig ¶
type RateLimiterConfig struct {
Limit int
Window time.Duration
Store RateLimiterStore
SkipFunc func(req *http.Request) bool
TrustProxies []string
}
RateLimiterConfig holds configuration for the rate limiter middleware.