middleware

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Auth

func Auth(authenticator Authenticator, next http.Handler) http.Handler

Auth wraps an HTTP handler with request authentication.

Types

type Authenticator

type Authenticator interface {
	Authenticate(r *http.Request) (Claims, error)
}

Authenticator validates request credentials.

type Claims

type Claims map[string]any

Claims stores authentication claims in request context.

func FromContext

func FromContext(ctx context.Context) (Claims, bool)

FromContext returns claims from context when available.

type Metrics

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

Metrics collects coarse-grained websocket endpoint metrics.

func (*Metrics) ConnClosed

func (m *Metrics) ConnClosed()

ConnClosed decrements active connection counter.

func (*Metrics) ConnOpened

func (m *Metrics) ConnOpened()

ConnOpened increments active connection counter.

func (*Metrics) Handle

func (m *Metrics) Handle(next http.Handler) http.Handler

Handle wraps an HTTP handler and records request-level metrics.

func (*Metrics) IncRejected

func (m *Metrics) IncRejected()

IncRejected increments rejected upgrade counter.

func (*Metrics) IncUpgrades

func (m *Metrics) IncUpgrades()

IncUpgrades increments successful upgrade counter.

func (*Metrics) Snapshot

func (m *Metrics) Snapshot() Snapshot

Snapshot returns current counter values.

type RateLimiter

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

RateLimiter applies per-key fixed-window rate limiting.

func NewRateLimiter

func NewRateLimiter(limit int, window time.Duration, keyFunc func(*http.Request) string) *RateLimiter

NewRateLimiter creates a simple in-process fixed-window limiter.

func (*RateLimiter) Handle

func (rl *RateLimiter) Handle(next http.Handler) http.Handler

Handle wraps next with rate limiting.

type Snapshot

type Snapshot struct {
	ActiveConnections int64
	RequestsTotal     int64
	RejectedTotal     int64
	UpgradesTotal     int64
	RequestNanosTotal int64
}

Snapshot is a copy of metrics values.

Jump to

Keyboard shortcuts

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