middleware

package
v0.0.0-...-c70600a Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DEFAULT_MAX_REQUESTS             = 100
	DEFAULT_TIME_FRAME_SECONDS       = 20
	DEFAULT_STALE_CLIENT_TTL_SECONDS = 300
)
View Source
const BASIC_AUTH_ROW_DELIMITER = "\n"

Variables

This section is empty.

Functions

func ContextWithLogger

func ContextWithLogger(ctx context.Context, l *slog.Logger) context.Context

ContextWithLogger returns a copy of ctx carrying l.

func ContextWithMiddlewareType

func ContextWithMiddlewareType(ctx context.Context, mwType string) context.Context

ContextWithMiddlewareType returns a copy of ctx carrying the middleware type name.

func LoggerFromContext

func LoggerFromContext(ctx context.Context) *slog.Logger

LoggerFromContext retrieves the logger stored by ContextWithLogger and, if a middleware type was stored via ContextWithMiddlewareType, automatically embeds it as a "middleware" attribute.

func NewLoggingResponseWriter

func NewLoggingResponseWriter(w http.ResponseWriter) *loggingResponseWriter

Types

type BasicAuthConfig

type BasicAuthConfig struct {
	File string `yaml:"file"`
	// contains filtered or unexported fields
}

func (*BasicAuthConfig) Exec

func (*BasicAuthConfig) Init

func (ba *BasicAuthConfig) Init(ctx context.Context) error

type CacheControlConfig

type CacheControlConfig struct {
	Duration string `yaml:"duration"`

	MaxItems uint `yaml:"max_items"`
	// contains filtered or unexported fields
}

func (*CacheControlConfig) Exec

func (*CacheControlConfig) Init

func (cc *CacheControlConfig) Init(ctx context.Context) error

type ClientRequestsCounter

type ClientRequestsCounter struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewClientRequestsCounter

func NewClientRequestsCounter() *ClientRequestsCounter

type LoggerConfig

type LoggerConfig struct {
	Stream StreamType `yaml:"stream"`
	Mode   LoggerMode `yaml:"mode"`
	// contains filtered or unexported fields
}

func (*LoggerConfig) Exec

func (*LoggerConfig) Init

func (l *LoggerConfig) Init(ctx context.Context) error

type LoggerMode

type LoggerMode string
const (
	LoggerModeJSON LoggerMode = "json"
	LoggerModeText            = "text"
)

type Middleware

type Middleware interface {
	Init(context.Context) error
	Exec(http.HandlerFunc) http.HandlerFunc
}

type MiddlewareType

type MiddlewareType string
const (
	LOGGER        MiddlewareType = "logger"
	RATE_LIMITER  MiddlewareType = "rate_limiter"
	BASIC_AUTH    MiddlewareType = "basic_auth"
	CACHE_CONTROL MiddlewareType = "cache_control"
	PROMETHEUS    MiddlewareType = "prometheus"
	WAF           MiddlewareType = "waf"
)

type PrometheusConfig

type PrometheusConfig struct {
	Route string `yaml:"route"`
	// contains filtered or unexported fields
}

PrometheusConfig is middleware that records per-route request metrics.

func (*PrometheusConfig) Exec

func (*PrometheusConfig) Init

func (p *PrometheusConfig) Init(ctx context.Context) error

type RateLimiterConfig

type RateLimiterConfig struct {
	MaxReqs                uint `yaml:"max_requests"`
	TimeFrameSecs          uint `yaml:"time_frame_seconds"`
	StaleClientTTLSeconds  uint `yaml:"stale_client_ttl_seconds,omitempty"`
	TrustProxyHeaders      bool `yaml:"trust_proxy_headers,omitempty"`
	ProxyHeaderMaxForwards int  `yaml:"proxy_header_max_forwards,omitempty"`
	// contains filtered or unexported fields
}

func (*RateLimiterConfig) Exec

func (*RateLimiterConfig) Init

func (rl *RateLimiterConfig) Init(ctx context.Context) error

func (*RateLimiterConfig) Stop

func (rl *RateLimiterConfig) Stop()

type StreamType

type StreamType string
const (
	StreamTypeStdout StreamType = "stdout"
	StreamTypeStderr            = "stderr"
)

type WAFConfig

type WAFConfig struct {
	Mode         WAFMode  `yaml:"mode"`           // "block" (default) | "log"
	Rules        []string `yaml:"rules"`          // which built-in rule sets to enable; empty = all
	MaxBodyBytes int64    `yaml:"max_body_bytes"` // max bytes of body to inspect; default 65536
	// contains filtered or unexported fields
}

WAFConfig implements a Web Application Firewall middleware that inspects requests for common attack patterns.

func (*WAFConfig) Exec

func (w *WAFConfig) Exec(next http.HandlerFunc) http.HandlerFunc

func (*WAFConfig) Init

func (w *WAFConfig) Init(ctx context.Context) error

type WAFMode

type WAFMode string
const (
	WAFModeBlock WAFMode = "block"
	WAFModeLog   WAFMode = "log"
)

Jump to

Keyboard shortcuts

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