Documentation
¶
Overview ¶
Package middlewares provides reusable middleware components for the requests HTTP client, including caching, cookie management, and header injection.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CacheMiddleware ¶
CacheMiddleware creates a middleware that caches GET responses.
func CookieMiddleware ¶
func CookieMiddleware(cookies []*http.Cookie) requests.Middleware
CookieMiddleware creates a middleware that adds the specified cookies to each request.
func HeaderMiddleware ¶
func HeaderMiddleware(headers http.Header) requests.Middleware
HeaderMiddleware creates a middleware that adds the specified headers to each request.
Types ¶
type CachedResponse ¶
CachedResponse represents a serializable HTTP response stored in the cache.
type Cacher ¶
type Cacher interface {
Get(key string) ([]byte, bool)
Set(key string, value []byte, ttl time.Duration)
Delete(key string)
}
Cacher is the interface for the cache.
type MemoryCache ¶
type MemoryCache struct {
// contains filtered or unexported fields
}
MemoryCache is an in-memory cache implementation with TTL-based expiration.
func NewMemoryCache ¶
func NewMemoryCache() *MemoryCache
NewMemoryCache creates a new MemoryCache and starts a background goroutine to clean expired items.
func (*MemoryCache) Close ¶ added in v0.3.5
func (c *MemoryCache) Close()
Close stops the background cleanup goroutine.
func (*MemoryCache) Delete ¶
func (c *MemoryCache) Delete(key string)
Delete removes a cache item by key.