Documentation
¶
Index ¶
- Constants
- func AuthMiddleware(store *sessions.CookieStore, sessionManager session.SessionManager, ...) func(http.Handler) http.Handler
- func CSRFProtection(next http.Handler) http.Handler
- func CompressMiddleware(next http.Handler) http.Handler
- func ConditionalMiddleware(next http.Handler) http.Handler
- func LoggingMiddleware(next http.Handler) http.Handler
- func NewLoggingMiddleware(logger *slog.Logger) func(http.Handler) http.Handler
- type AuthConfig
Constants ¶
const (
// MinCompressSize is the minimum response size for compression (in bytes)
MinCompressSize = 512
)
Variables ¶
This section is empty.
Functions ¶
func AuthMiddleware ¶
func AuthMiddleware(store *sessions.CookieStore, sessionManager session.SessionManager, config *AuthConfig) func(http.Handler) http.Handler
AuthMiddleware creates a middleware that protects routes by checking for a valid session. If the user is not authenticated, it returns 401 Unauthorized. It accepts a session store for checking authentication and a session manager for clearing sessions.
func CSRFProtection ¶
CSRFProtection enforces a same-origin check on unsafe HTTP methods. For non-idempotent methods it requires an Origin header that matches the request host (including port). If the check fails, it returns 403.
func CompressMiddleware ¶
CompressMiddleware wraps handler with compression support
func ConditionalMiddleware ¶
ConditionalMiddleware handles If-None-Match and If-Modified-Since requests Returns 304 Not Modified if validators match, otherwise calls the next handler This middleware must be placed AFTER handlers that set validators (ETag, Last-Modified) For now, we'll let handlers execute and then check validators in a wrapper
func LoggingMiddleware ¶
LoggingMiddleware creates a middleware that logs every request received and response sent. It uses the default slog logger. For custom logger support, use NewLoggingMiddleware.
Types ¶
type AuthConfig ¶
type AuthConfig struct {
// DebugDelayMS is an optional debug delay in milliseconds to add to requests.
// If IsSet is false or value is 0, no delay is added.
DebugDelayMS struct {
IsSet bool
Int int
}
}
AuthConfig holds configuration for auth middleware behavior.