middleware

package
v0.50.1 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

Package middleware provides HTTP middleware for the azugo framework.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CORS

CORS is a middleware for handling CORS requests.

func Metrics

func Metrics(path string, options ...MetricsOption) azugo.RequestHandlerFunc

Metrics initializes and returns metrics middleware.

func RateLimit added in v0.33.0

RateLimit applies a request rate limit per client.

CORS preflight requests flagged by the CORS middleware are exempt.

func ReadTimeout added in v0.41.0

ReadTimeout gives the guarded routes duration to read the request body instead of the server ReadTimeout.

func RealIP

RealIP middleware updates request remote IP address based on X-Real-IP and X-Forwarded-For headers.

func RequestLogger

func RequestLogger(next azugo.RequestHandler) azugo.RequestHandler

RequestLogger is a middleware that logs HTTP requests.

func WriteTimeout added in v0.41.0

func WriteTimeout(d time.Duration) func(azugo.RequestHandler) azugo.RequestHandler

WriteTimeout gives the guarded routes duration to write the response instead of the server WriteTimeout.

Types

type MetricsOption

type MetricsOption interface {
	// contains filtered or unexported methods
}

MetricsOption is an interface for metrics handler options.

type MetricsSubsystem

type MetricsSubsystem string

MetricsSubsystem represents subsystem name for metric structuring.

type RateLimitError added in v0.33.0

type RateLimitError struct {
	// Result is the rate limiter outcome that triggered the rejection.
	Result ratelimit.Result
	// contains filtered or unexported fields
}

RateLimitError is returned by the RateLimit middleware when a request exceeds the configured limit.

func (*RateLimitError) Error added in v0.33.0

func (*RateLimitError) Error() string

Error implements the error interface.

func (*RateLimitError) ErrorHeaders added in v0.33.0

func (e *RateLimitError) ErrorHeaders() iter.Seq2[string, string]

ErrorHeaders returns the RateLimit response headers to set on the response.

func (*RateLimitError) SafeError added in v0.33.0

func (*RateLimitError) SafeError() string

SafeError returns a message that can be safely returned to the client.

func (*RateLimitError) StatusCode added in v0.33.0

func (*RateLimitError) StatusCode() int

StatusCode returns the HTTP status code for the rate limit error.

type RateLimitKeyGenerator added in v0.33.0

type RateLimitKeyGenerator func(ctx *azugo.Context) (string, error)

RateLimitKeyGenerator is a function that generates a rate limit key for a request.

type RateLimitName added in v0.33.0

type RateLimitName string

RateLimitName sets the limiter name used for key namespacing in the cache backend. Defaults to "global".

type RateLimitOption added in v0.33.0

type RateLimitOption interface {
	// contains filtered or unexported methods
}

RateLimitOption configures the rate limit middleware.

func DisableRateLimitHeaders added in v0.33.0

func DisableRateLimitHeaders() RateLimitOption

DisableRateLimitHeaders disables ratelimit response headers.

type RateLimitResolver added in v0.34.0

type RateLimitResolver func(ctx *azugo.Context) int

RateLimitResolver allows to prived custom resolver for context based custom limits. If zero is returned default configured limit is used.

Jump to

Keyboard shortcuts

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