middleware

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CacheBackend

type CacheBackend interface {
	Get(key string) ([]byte, bool)
	Set(key string, value []byte, ttl time.Duration) error
	Delete(key string) error
	Clear() error
}

CacheBackend interface for cache middleware

type CompressedWriter

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

CompressedWriter wraps an io.Writer with gzip compression

func NewCompressedWriter

func NewCompressedWriter(w io.Writer, level int) (*CompressedWriter, error)

func (*CompressedWriter) Close

func (cw *CompressedWriter) Close() error

func (*CompressedWriter) Write

func (cw *CompressedWriter) Write(p []byte) (n int, err error)

type DefaultLogger

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

DefaultLogger provides a simple logger implementation

func NewDefaultLogger

func NewDefaultLogger() *DefaultLogger

func (*DefaultLogger) Debug

func (dl *DefaultLogger) Debug(msg string, args ...interface{})

func (*DefaultLogger) Error

func (dl *DefaultLogger) Error(msg string, args ...interface{})

func (*DefaultLogger) Info

func (dl *DefaultLogger) Info(msg string, args ...interface{})

type DownloadRequest

type DownloadRequest struct {
	URL         string
	Destination string
	Options     *types.DownloadOptions
	Headers     map[string]string
	UserAgent   string
	Metadata    map[string]interface{}
}

DownloadRequest contains the download request information

type DownloadResponse

type DownloadResponse struct {
	Stats    *types.DownloadStats
	Headers  map[string][]string
	Metadata map[string]interface{}
	Cached   bool
}

DownloadResponse contains the download response information

type Handler

type Handler func(ctx context.Context, req *DownloadRequest) (*DownloadResponse, error)

Handler represents a download handler function

type Logger

type Logger interface {
	Info(msg string, args ...interface{})
	Error(msg string, args ...interface{})
	Debug(msg string, args ...interface{})
}

Logger interface for logging middleware

type MemoryCache

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

MemoryCache provides a simple in-memory cache implementation

func NewMemoryCache

func NewMemoryCache() *MemoryCache

func (*MemoryCache) Clear

func (mc *MemoryCache) Clear() error

func (*MemoryCache) Delete

func (mc *MemoryCache) Delete(key string) error

func (*MemoryCache) Get

func (mc *MemoryCache) Get(key string) ([]byte, bool)

func (*MemoryCache) Set

func (mc *MemoryCache) Set(key string, value []byte, ttl time.Duration) error

type MetricsCollector

type MetricsCollector interface {
	IncrementCounter(name string, tags map[string]string)
	RecordDuration(name string, duration time.Duration, tags map[string]string)
	RecordGauge(name string, value float64, tags map[string]string)
}

MetricsCollector interface for metrics middleware

type Middleware

type Middleware func(next Handler) Handler

Middleware represents a middleware function that wraps a Handler

func AuthenticationMiddleware

func AuthenticationMiddleware(auth plugin.AuthPlugin) Middleware

AuthenticationMiddleware creates an authentication middleware

func CacheMiddleware

func CacheMiddleware(cache CacheBackend, ttl time.Duration) Middleware

CacheMiddleware creates a cache middleware

func CompressionMiddleware

func CompressionMiddleware(level int) Middleware

CompressionMiddleware creates a compression middleware

func LoggingMiddleware

func LoggingMiddleware(logger Logger) Middleware

LoggingMiddleware creates a logging middleware

func MetricsMiddleware

func MetricsMiddleware(collector MetricsCollector) Middleware

MetricsMiddleware creates a metrics collection middleware

func RateLimitMiddleware

func RateLimitMiddleware(limiter RateLimiter) Middleware

RateLimitMiddleware creates a rate limiting middleware

func RetryMiddleware

func RetryMiddleware(maxRetries int, delay time.Duration) Middleware

RetryMiddleware creates a retry middleware

func TimeoutMiddleware

func TimeoutMiddleware(timeout time.Duration) Middleware

TimeoutMiddleware creates a timeout middleware

type MiddlewareChain

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

MiddlewareChain manages a chain of middleware

func NewMiddlewareChain

func NewMiddlewareChain() *MiddlewareChain

NewMiddlewareChain creates a new middleware chain

func (*MiddlewareChain) Clear

func (mc *MiddlewareChain) Clear()

Clear removes all middleware from the chain

func (*MiddlewareChain) Count

func (mc *MiddlewareChain) Count() int

Count returns the number of middleware in the chain

func (*MiddlewareChain) Then

func (mc *MiddlewareChain) Then(handler Handler) Handler

Then applies all middleware to the final handler and returns the wrapped handler

func (*MiddlewareChain) Use

func (mc *MiddlewareChain) Use(m Middleware)

Use adds a middleware to the chain

type RateLimiter

type RateLimiter interface {
	Allow() bool
	Wait(ctx context.Context) error
}

RateLimiter interface for rate limiting

Jump to

Keyboard shortcuts

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