Documentation
¶
Index ¶
- Constants
- func ContextWithLogger(ctx context.Context, l *slog.Logger) context.Context
- func ContextWithMiddlewareType(ctx context.Context, mwType string) context.Context
- func LoggerFromContext(ctx context.Context) *slog.Logger
- func NewLoggingResponseWriter(w http.ResponseWriter) *loggingResponseWriter
- type BasicAuthConfig
- type CacheControlConfig
- type ClientRequestsCounter
- type LoggerConfig
- type LoggerMode
- type Middleware
- type MiddlewareType
- type PrometheusConfig
- type RateLimiterConfig
- type StreamType
- type WAFConfig
- type WAFMode
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 ¶
ContextWithLogger returns a copy of ctx carrying l.
func ContextWithMiddlewareType ¶
ContextWithMiddlewareType returns a copy of ctx carrying the middleware type name.
func LoggerFromContext ¶
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 (ba *BasicAuthConfig) Exec(next http.HandlerFunc) http.HandlerFunc
type CacheControlConfig ¶
type CacheControlConfig struct {
Duration string `yaml:"duration"`
MaxItems uint `yaml:"max_items"`
// contains filtered or unexported fields
}
func (*CacheControlConfig) Exec ¶
func (cc *CacheControlConfig) Exec(next http.HandlerFunc) http.HandlerFunc
type ClientRequestsCounter ¶
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 (l *LoggerConfig) Exec(next http.HandlerFunc) http.HandlerFunc
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 (p *PrometheusConfig) Exec(next http.HandlerFunc) http.HandlerFunc
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 (rl *RateLimiterConfig) Exec(next http.HandlerFunc) http.HandlerFunc
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
Click to show internal directories.
Click to hide internal directories.