middlewares

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2025 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AccessControlAllowOriginHeader      = "Access-Control-Allow-Origin"
	AccessControlAllowCredentialsHeader = "Access-Control-Allow-Credentials"
	AccessControlAllowHeadersHeader     = "Access-Control-Allow-Headers"
	AccessControlAllowMethodsHeader     = "Access-Control-Allow-Methods"
)

Constants for CORS headers.

View Source
const (
	ClientAddr       httpfx.ContextKey = "client-addr"
	ClientAddrIP     httpfx.ContextKey = "client-addr-ip"
	ClientAddrOrigin httpfx.ContextKey = "client-addr-origin"
)
View Source
const (
	ContextKeyAuthClaims httpfx.ContextKey = "claims"
)
View Source
const CorrelationIDHeader = "X-Correlation-ID"
View Source
const ResponseTimeHeader = "X-Request-Time"

Variables

View Source
var ErrInvalidSigningMethod = errors.New("invalid signing method")

Functions

func AuthMiddleware

func AuthMiddleware() httpfx.Handler

func CorrelationIDMiddleware added in v0.7.0

func CorrelationIDMiddleware() httpfx.Handler

func CorsMiddleware

func CorsMiddleware(options ...CorsOption) httpfx.Handler

CorsMiddleware creates a CORS middleware using functional options.

func ErrorHandlerMiddleware

func ErrorHandlerMiddleware() httpfx.Handler

func GetClientAddrs

func GetClientAddrs(req *http.Request) string

func GetCorrelationIDFromContext added in v0.7.2

func GetCorrelationIDFromContext(ctx context.Context) string

GetCorrelationIDFromContext extracts correlation ID from context.

func LoggingMiddleware added in v0.7.2

func LoggingMiddleware(logger *logfx.Logger) httpfx.Handler

LoggingMiddleware creates HTTP request logging middleware that integrates with correlation ID.

func MetricsMiddleware

func MetricsMiddleware(httpMetrics *httpfx.Metrics) httpfx.Handler

MetricsMiddleware creates HTTP metrics middleware using the simplified MetricsBuilder approach.

func RateLimitMiddleware added in v0.6.29

func RateLimitMiddleware(options ...RateLimitOption) httpfx.Handler

RateLimitMiddleware creates a rate limiting middleware using functional options.

func ResolveAddressMiddleware

func ResolveAddressMiddleware() httpfx.Handler

func ResponseTimeMiddleware

func ResponseTimeMiddleware() httpfx.Handler

Types

type CorsOption added in v0.6.29

type CorsOption func(*corsConfig)

CorsOption is a function type that modifies the corsConfig.

func WithAllowCredentials added in v0.6.29

func WithAllowCredentials(allow bool) CorsOption

WithAllowCredentials sets the Access-Control-Allow-Credentials header.

func WithAllowHeaders added in v0.6.29

func WithAllowHeaders(headers []string) CorsOption

WithAllowHeaders sets the Access-Control-Allow-Headers header.

func WithAllowMethods added in v0.6.29

func WithAllowMethods(methods []string) CorsOption

WithAllowMethods sets the Access-Control-Allow-Methods header.

func WithAllowOrigin added in v0.6.29

func WithAllowOrigin(origin string) CorsOption

WithAllowOrigin sets the Access-Control-Allow-Origin header. If not set, defaults to "*".

type RateLimitOption added in v0.6.29

type RateLimitOption func(*rateLimitConfig)

RateLimitOption defines a functional option for configuring rate limiting.

func WithRateLimiterIPKeyFunc added in v0.6.29

func WithRateLimiterIPKeyFunc() RateLimitOption

WithRateLimiterIPKeyFunc sets the key function to extract IP addresses for rate limiting.

func WithRateLimiterKeyFunc added in v0.6.29

func WithRateLimiterKeyFunc(keyFunc func(*httpfx.Context) string) RateLimitOption

WithRateLimiterKeyFunc sets the key extraction function for rate limiting.

func WithRateLimiterRequestsPerMinute added in v0.6.29

func WithRateLimiterRequestsPerMinute(requests int) RateLimitOption

WithRateLimiterRequestsPerMinute sets the number of requests allowed per minute.

func WithRateLimiterWindowSize added in v0.6.29

func WithRateLimiterWindowSize(duration time.Duration) RateLimitOption

WithRateLimiterWindowSize sets the time window for rate limiting.

func WithUserKeyFunc added in v0.6.29

func WithUserKeyFunc(userIDExtractor func(*httpfx.Context) string) RateLimitOption

WithUserKeyFunc sets the key function to extract user IDs for rate limiting.

Jump to

Keyboard shortcuts

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