middleware

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BackendKey contextKey = iota
	RetryKey
)
View Source
const TargetHost string = "target_host"

Variables

This section is empty.

Functions

func CORSMiddleware

func CORSMiddleware(config CORSConfig) func(http.Handler) http.Handler

func CompressionMiddleware

func CompressionMiddleware(next http.Handler) http.Handler

func GetTargetHost

func GetTargetHost(r *http.Request) string

func SecurityMiddleware

func SecurityMiddleware(config SecurityConfig) func(http.Handler) http.Handler

Types

type BackendState added in v0.1.4

type BackendState struct {
	// contains filtered or unexported fields
}

BackendState holds the state and failure information for a single backend.

type CORSConfig

type CORSConfig struct {
	AllowedOrigins   []string
	AllowedMethods   []string
	AllowedHeaders   []string
	ExposedHeaders   []string
	AllowCredentials bool
	MaxAge           int
}

type CircuitBreaker

type CircuitBreaker struct {
	// contains filtered or unexported fields
}

func NewCircuitBreaker

func NewCircuitBreaker(threshold int, timeout time.Duration) *CircuitBreaker

func (*CircuitBreaker) Middleware

func (cb *CircuitBreaker) Middleware(next http.Handler) http.Handler

Middleware wraps the HTTP handler with circuit breaker logic.

type LoggingMiddleware

type LoggingMiddleware struct {
	// contains filtered or unexported fields
}

LoggingMiddleware handles logging of HTTP requests.

func NewLoggingMiddleware

func NewLoggingMiddleware(logger *zap.Logger, opts ...LoggingOption) *LoggingMiddleware

func (*LoggingMiddleware) Middleware

func (l *LoggingMiddleware) Middleware(next http.Handler) http.Handler

type LoggingOption

type LoggingOption func(*LoggingMiddleware)

func WithExcludePaths

func WithExcludePaths(paths []string) LoggingOption

excludes specified paths from logging.

func WithHeaders

func WithHeaders() LoggingOption

enables logging of request headers.

func WithLogLevel

func WithLogLevel(level zapcore.Level) LoggingOption

func WithQueryParams

func WithQueryParams() LoggingOption

enables logging of query parameters.

type Middleware

type Middleware interface {
	Middleware(next http.Handler) http.Handler
}

func NewRateLimiterMiddleware

func NewRateLimiterMiddleware(rps float64, burst int) Middleware

type MiddlewareChain

type MiddlewareChain struct {
	// contains filtered or unexported fields
}

Chain multiple middleware

func NewMiddlewareChain

func NewMiddlewareChain(middlewares ...Middleware) *MiddlewareChain

func (*MiddlewareChain) Then

func (c *MiddlewareChain) Then(final http.Handler) http.Handler

type RateLimiterMiddleware

type RateLimiterMiddleware struct {
	// contains filtered or unexported fields
}

func (*RateLimiterMiddleware) Middleware

func (m *RateLimiterMiddleware) Middleware(next http.Handler) http.Handler

type SecurityConfig

type SecurityConfig struct {
	HSTS                  bool
	HSTSMaxAge            int
	HSTSIncludeSubDomains bool
	HSTSPreload           bool
	FrameOptions          string
	ContentTypeOptions    bool
	XSSProtection         bool
}

type ServerHostMiddleware

type ServerHostMiddleware struct{}

func NewServerHostMiddleware

func NewServerHostMiddleware() *ServerHostMiddleware

func (*ServerHostMiddleware) Middleware

func (m *ServerHostMiddleware) Middleware(next http.Handler) http.Handler

Jump to

Keyboard shortcuts

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