middlewares

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
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 GetClaims

func GetClaims[T any](c *aether.Context[T]) jwt.Claims

GetClaims retrieves JWT claims from the request context.

func GetMapClaims

func GetMapClaims[T any](c *aether.Context[T]) jwt.MapClaims

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

type JWTValidator interface {
	Validate(tokenString string) (jwt.Claims, error)
}

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.

func (*MemoryRateLimiterStore) Increment

func (s *MemoryRateLimiterStore) Increment(key string, window time.Duration) (int, error)

Increment increases the counter for the given key within the time window.

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.

type RateLimiterStore

type RateLimiterStore interface {
	Increment(key string, window time.Duration) (int, error)
}

RateLimiterStore defines the interface for rate limiting storage.

Jump to

Keyboard shortcuts

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