middleware

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2024 License: MIT Imports: 17 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 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

type LogEntry

type LogEntry struct {
	Timestamp   string            `json:"timestamp"`
	Method      string            `json:"method"`
	Path        string            `json:"path"`
	Status      int               `json:"status"`
	Duration    string            `json:"duration"`
	IP          string            `json:"ip"`
	UserAgent   string            `json:"user_agent"`
	QueryParams map[string]string `json:"query_params,omitempty"`
	Headers     map[string]string `json:"headers,omitempty"`
	Level       string            `json:"level"`
	Error       string            `json:"error,omitempty"`
}

type LogLevel

type LogLevel int
const (
	INFO LogLevel = iota
	WARNING
	ERROR
)

type LogStatusWriter

type LogStatusWriter struct {
	http.ResponseWriter
	// contains filtered or unexported fields
}

func (*LogStatusWriter) WriteHeader

func (w *LogStatusWriter) WriteHeader(status int)

type LoggingMiddleware

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

func NewLoggingMiddleware

func NewLoggingMiddleware(logger *log.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

func WithHeaders

func WithHeaders() LoggingOption

func WithLogLevel

func WithLogLevel(level LogLevel) LoggingOption

func WithQueryParams

func WithQueryParams() LoggingOption

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

type TracingMiddleware

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

func NewTracingMiddleware

func NewTracingMiddleware(serviceName string) *TracingMiddleware

func (*TracingMiddleware) Middleware

func (t *TracingMiddleware) Middleware(next http.Handler) http.Handler

Jump to

Keyboard shortcuts

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