middleware

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const RequestIDKey contextKey = "request_id"

Variables

This section is empty.

Functions

func ClientIP

func ClientIP(r *http.Request) string

ClientIP extracts the client IP from the request's RemoteAddr.

func GetRequestID

func GetRequestID(ctx context.Context) string

func Logging

func Logging(next http.Handler) http.Handler

func RequestID

func RequestID(next http.Handler) http.Handler

Types

type RateLimiter

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

RateLimiter is a simple in-memory fixed-window limiter keyed by a function of the request (client IP by default). It bounds token-exchange / token-mint abuse. In a multi-replica deployment this is per-process; back it with a shared store (e.g. Redis) for a global limit — documented as a known limitation.

func NewRateLimiter

func NewRateLimiter(limit int, interval time.Duration, keyFn func(*http.Request) string) *RateLimiter

NewRateLimiter allows up to limit requests per interval per key.

func (*RateLimiter) Middleware

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

Middleware enforces the limit, returning 429 when exceeded.

Jump to

Keyboard shortcuts

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