middleware

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package middleware provides HTTP middleware for ChronosOS.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CORS

func CORS(cfg CORSConfig) func(http.Handler) http.Handler

CORS returns middleware that handles Cross-Origin Resource Sharing.

func IPKeyFunc

func IPKeyFunc(r *http.Request) string

IPKeyFunc extracts the client IP for rate limiting.

func RateLimit

func RateLimit(cfg RateLimitConfig) func(http.Handler) http.Handler

RateLimit returns middleware that limits requests using a fixed-window counter.

Types

type CORSConfig

type CORSConfig struct {
	AllowOrigins     []string
	AllowMethods     []string
	AllowHeaders     []string
	ExposeHeaders    []string
	AllowCredentials bool
	MaxAge           int
}

CORSConfig holds CORS middleware configuration.

func DefaultCORSConfig

func DefaultCORSConfig() CORSConfig

DefaultCORSConfig returns a permissive CORS config suitable for development.

type RateLimitConfig

type RateLimitConfig struct {
	RequestsPerWindow int
	Window            time.Duration
	KeyFunc           func(r *http.Request) string
}

RateLimitConfig holds configuration for the rate limiter.

func DefaultRateLimitConfig

func DefaultRateLimitConfig() RateLimitConfig

DefaultRateLimitConfig returns a rate limiter that allows 100 requests per minute keyed by client IP.

Jump to

Keyboard shortcuts

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