middleware

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2025 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

Logger logs request details after handling. Uses NopLogger by default; use LoggerWithLogger to inject a real logger.

Recovery catches panics and returns an error response. Uses NopLogger by default; use RecoveryWithLogger to inject a real logger.

Functions

func Auth

Auth requires the client to be authenticated.

func CleanupClientLimiters deprecated

func CleanupClientLimiters(client *websocket.Client)

CleanupClientLimiters is deprecated.

Deprecated: Use RateLimiterStore.Remove with Hub's WithClientDisconnectCallback instead.

func LoggerWithLogger

func LoggerWithLogger(logger websocket.Logger) websocket.Middleware

LoggerWithLogger logs request details after handling using the provided logger.

func LoginStateUpdater

func LoginStateUpdater(next websocket.Handler) websocket.Handler

LoginStateUpdater updates client state after successful login. It reads login info from context (set by handler via SetLoginInfo) and updates client state and notifies the hub.

func RateLimit

func RateLimit(cfg *RateLimitConfig) websocket.Middleware

RateLimit creates a rate limit middleware with a new store. Note: For proper cleanup, use RateLimitWithStore with Hub's WithClientDisconnectCallback.

func RateLimitWithStore

func RateLimitWithStore(cfg *RateLimitConfig, store *RateLimiterStore) websocket.Middleware

RateLimitWithStore creates a rate limit middleware with custom store.

func RecoveryWithLogger

func RecoveryWithLogger(logger websocket.Logger) websocket.Middleware

RecoveryWithLogger catches panics and returns an error response using the provided logger.

func RequestID

func RequestID(next websocket.Handler) websocket.Handler

RequestID adds request ID to context. Uses client-provided ID if present, otherwise generates UUID.

Types

type RateLimitConfig

type RateLimitConfig struct {
	Default float64            // Default requests per second (0 = unlimited)
	Methods map[string]float64 // Per-method limits (0 = unlimited)
}

RateLimitConfig configures rate limiting.

type RateLimiterStore

type RateLimiterStore struct {
	// contains filtered or unexported fields
}

RateLimiterStore manages per-client rate limiters.

func NewRateLimiterStore

func NewRateLimiterStore() *RateLimiterStore

NewRateLimiterStore creates a new rate limiter store.

func (*RateLimiterStore) Remove

func (s *RateLimiterStore) Remove(client *websocket.Client)

Remove removes all limiters for a client. Call this on client disconnect.

Jump to

Keyboard shortcuts

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