Documentation
¶
Index ¶
- Constants
- Variables
- func AuthMiddleware() httpfx.Handler
- func CorrelationIDMiddleware() httpfx.Handler
- func CorsMiddleware(options ...CorsOption) httpfx.Handler
- func ErrorHandlerMiddleware() httpfx.Handler
- func GetClientAddrs(req *http.Request) string
- func GetCorrelationIDFromContext(ctx context.Context) string
- func LoggingMiddleware(logger *logfx.Logger) httpfx.Handler
- func MetricsMiddleware(httpMetrics *httpfx.Metrics) httpfx.Handler
- func RateLimitMiddleware(options ...RateLimitOption) httpfx.Handler
- func ResolveAddressMiddleware() httpfx.Handler
- func ResponseTimeMiddleware() httpfx.Handler
- type CorsOption
- type RateLimitOption
- func WithRateLimiterIPKeyFunc() RateLimitOption
- func WithRateLimiterKeyFunc(keyFunc func(*httpfx.Context) string) RateLimitOption
- func WithRateLimiterRequestsPerMinute(requests int) RateLimitOption
- func WithRateLimiterWindowSize(duration time.Duration) RateLimitOption
- func WithUserKeyFunc(userIDExtractor func(*httpfx.Context) string) RateLimitOption
Constants ¶
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.
const ( ClientAddr httpfx.ContextKey = "client-addr" ClientAddrIP httpfx.ContextKey = "client-addr-ip" ClientAddrOrigin httpfx.ContextKey = "client-addr-origin" )
const (
ContextKeyAuthClaims httpfx.ContextKey = "claims"
)
const CorrelationIDHeader = "X-Correlation-ID"
const ResponseTimeHeader = "X-Request-Time"
Variables ¶
var ErrInvalidSigningMethod = errors.New("invalid signing method")
Functions ¶
func AuthMiddleware ¶
func CorrelationIDMiddleware ¶ added in v0.7.0
func CorsMiddleware ¶
func CorsMiddleware(options ...CorsOption) httpfx.Handler
CorsMiddleware creates a CORS middleware using functional options.
func ErrorHandlerMiddleware ¶
func GetClientAddrs ¶
func GetCorrelationIDFromContext ¶ added in v0.7.2
GetCorrelationIDFromContext extracts correlation ID from context.
func LoggingMiddleware ¶ added in v0.7.2
LoggingMiddleware creates HTTP request logging middleware that integrates with correlation ID.
func MetricsMiddleware ¶
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 ResponseTimeMiddleware ¶
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.