Documentation
¶
Index ¶
- func Bool(v bool) *bool
- func DefaultCacheKeyFunc(method, fullURL string, _ map[string]string) string
- func SetBaseURL(baseURL string)
- type Auth
- type Cache
- type CacheConfig
- type CacheEntry
- type CacheKeyFunc
- type CacheStats
- type Client
- type DefaultLogger
- type InterceptorOptions
- type LogLevel
- type LogOptions
- type Logger
- type MemoryCache
- type MemoryCacheOptions
- type ProgressReader
- type ProgressWriter
- type Promise
- func DeleteAsync(urlStr string, options ...*RequestOptions) *Promise
- func GetAsync(urlStr string, options ...*RequestOptions) *Promise
- func HeadAsync(urlStr string, options ...*RequestOptions) *Promise
- func NewPromise() *Promise
- func OptionsAsync(urlStr string, options ...*RequestOptions) *Promise
- func PatchAsync(urlStr string, body interface{}, options ...*RequestOptions) *Promise
- func PostAsync(urlStr string, body interface{}, options ...*RequestOptions) *Promise
- func PutAsync(urlStr string, body interface{}, options ...*RequestOptions) *Promise
- func RequestAsync(method, urlStr string, options ...*RequestOptions) *Promise
- type Proxy
- type RequestCacheOptions
- type RequestInterceptors
- type RequestOptions
- type Response
- func Delete(urlStr string, options ...*RequestOptions) (*Response, error)
- func Get(urlStr string, options ...*RequestOptions) (*Response, error)
- func Head(urlStr string, options ...*RequestOptions) (*Response, error)
- func Options(urlStr string, options ...*RequestOptions) (*Response, error)
- func Patch(urlStr string, body interface{}, options ...*RequestOptions) (*Response, error)
- func Post(urlStr string, body interface{}, options ...*RequestOptions) (*Response, error)
- func Put(urlStr string, body interface{}, options ...*RequestOptions) (*Response, error)
- func Request(method, urlStr string, options ...*RequestOptions) (*Response, error)
- type ResponseInterceptors
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultCacheKeyFunc ¶ added in v0.6.7
DefaultCacheKeyFunc generates a cache key from method and full URL
func SetBaseURL ¶
func SetBaseURL(baseURL string)
Types ¶
type Cache ¶ added in v0.6.7
type Cache interface {
// Get retrieves a cached response by key. Returns nil if not found or expired.
Get(key string) *CacheEntry
// Set stores a response in the cache with the given key and TTL.
Set(key string, entry *CacheEntry, ttl time.Duration)
// Delete removes an entry from the cache.
Delete(key string)
// Clear removes all entries from the cache.
Clear()
// Stats returns cache statistics.
Stats() CacheStats
}
Cache defines the interface for cache implementations. Users can implement this interface for custom storage backends (Redis, file, etc.)
type CacheConfig ¶ added in v0.6.7
type CacheConfig struct {
// Cache is the cache implementation to use
Cache Cache
// DefaultTTL is the default TTL for cached responses when per-request TTL is not specified
// A value of 0 means no default TTL (must be specified per-request)
DefaultTTL time.Duration
// KeyFunc is a custom function to generate cache keys
// If nil, the default key function (Method + URL) is used
KeyFunc CacheKeyFunc
// CacheableMethods defines which HTTP methods can be cached
// If nil, defaults to []string{"GET"}
CacheableMethods []string
}
CacheConfig holds the global cache configuration for a Client
type CacheEntry ¶ added in v0.6.7
type CacheEntry struct {
Body []byte
StatusCode int
Headers http.Header
CreatedAt time.Time
ExpiresAt time.Time
}
CacheEntry represents a cached HTTP response
func (*CacheEntry) IsExpired ¶ added in v0.6.7
func (e *CacheEntry) IsExpired() bool
IsExpired checks if the cache entry has expired
type CacheKeyFunc ¶ added in v0.6.7
CacheKeyFunc is a function type for generating cache keys
type CacheStats ¶ added in v0.6.7
CacheStats provides cache statistics
type Client ¶
type Client struct {
BaseURL string
HTTPClient *http.Client
Logger Logger
CacheConfig *CacheConfig
}
func NewClientWithCache ¶ added in v0.6.7
func NewClientWithCache(baseURL string, cacheConfig *CacheConfig) *Client
NewClientWithCache creates a client with cache enabled
func (*Client) CacheStats ¶ added in v0.6.7
func (c *Client) CacheStats() *CacheStats
CacheStats returns the cache statistics
func (*Client) ClearCache ¶ added in v0.6.7
func (c *Client) ClearCache()
ClearCache clears all entries in the client's cache
func (*Client) SetCache ¶ added in v0.6.7
func (c *Client) SetCache(config *CacheConfig)
SetCache sets the cache configuration for the client
type DefaultLogger ¶ added in v0.6.0
type DefaultLogger struct {
// contains filtered or unexported fields
}
func NewDefaultLogger ¶ added in v0.6.0
func NewDefaultLogger(options LogOptions) *DefaultLogger
func (*DefaultLogger) LogError ¶ added in v0.6.0
func (l *DefaultLogger) LogError(err error, level LogLevel)
func (*DefaultLogger) LogRequest ¶ added in v0.6.0
func (l *DefaultLogger) LogRequest(req *http.Request, level LogLevel)
func (*DefaultLogger) LogResponse ¶ added in v0.6.0
func (*DefaultLogger) SetLevel ¶ added in v0.6.0
func (l *DefaultLogger) SetLevel(level LogLevel)
type InterceptorOptions ¶ added in v0.3.0
type InterceptorOptions struct {
RequestInterceptors RequestInterceptors
ResponseInterceptors ResponseInterceptors
}
type LogOptions ¶ added in v0.6.0
type Logger ¶ added in v0.6.0
type MemoryCache ¶ added in v0.6.7
type MemoryCache struct {
// contains filtered or unexported fields
}
MemoryCache is a thread-safe in-memory cache implementation
func NewMemoryCache ¶ added in v0.6.7
func NewMemoryCache(opts *MemoryCacheOptions) *MemoryCache
NewMemoryCache creates a new in-memory cache
func (*MemoryCache) Clear ¶ added in v0.6.7
func (c *MemoryCache) Clear()
Clear removes all entries from the cache
func (*MemoryCache) Close ¶ added in v0.6.7
func (c *MemoryCache) Close()
Close stops the background cleanup goroutine
func (*MemoryCache) Delete ¶ added in v0.6.7
func (c *MemoryCache) Delete(key string)
Delete removes an entry from the cache
func (*MemoryCache) Get ¶ added in v0.6.7
func (c *MemoryCache) Get(key string) *CacheEntry
Get retrieves a cached response by key
func (*MemoryCache) Set ¶ added in v0.6.7
func (c *MemoryCache) Set(key string, entry *CacheEntry, ttl time.Duration)
Set stores a response in the cache
func (*MemoryCache) Stats ¶ added in v0.6.7
func (c *MemoryCache) Stats() CacheStats
Stats returns cache statistics
type MemoryCacheOptions ¶ added in v0.6.7
type MemoryCacheOptions struct {
// MaxSize is the maximum number of entries (0 = unlimited)
MaxSize int
// CleanupInterval is how often to clean expired entries (default: 5 minutes)
CleanupInterval time.Duration
}
MemoryCacheOptions configures the MemoryCache
type ProgressReader ¶ added in v0.5.0
type ProgressReader struct {
// contains filtered or unexported fields
}
type ProgressWriter ¶ added in v0.5.0
type ProgressWriter struct {
// contains filtered or unexported fields
}
type Promise ¶
type Promise struct {
// contains filtered or unexported fields
}
func DeleteAsync ¶
func DeleteAsync(urlStr string, options ...*RequestOptions) *Promise
func GetAsync ¶
func GetAsync(urlStr string, options ...*RequestOptions) *Promise
func HeadAsync ¶
func HeadAsync(urlStr string, options ...*RequestOptions) *Promise
func NewPromise ¶
func NewPromise() *Promise
func OptionsAsync ¶
func OptionsAsync(urlStr string, options ...*RequestOptions) *Promise
func PatchAsync ¶
func PatchAsync(urlStr string, body interface{}, options ...*RequestOptions) *Promise
func PostAsync ¶
func PostAsync(urlStr string, body interface{}, options ...*RequestOptions) *Promise
func PutAsync ¶
func PutAsync(urlStr string, body interface{}, options ...*RequestOptions) *Promise
func RequestAsync ¶
func RequestAsync(method, urlStr string, options ...*RequestOptions) *Promise
type RequestCacheOptions ¶ added in v0.6.7
type RequestCacheOptions struct {
// Enabled explicitly enables/disables caching for this request
// If nil, caching is disabled (opt-in model)
Enabled *bool
// TTL sets the TTL for this specific request
// Overrides the global DefaultTTL if set
TTL time.Duration
// ForceRefresh bypasses the cache and fetches fresh data
// The fresh response will still be cached
ForceRefresh bool
// CustomKey allows overriding the cache key for this request
CustomKey string
}
RequestCacheOptions holds per-request cache configuration
func CacheDisabled ¶ added in v0.6.7
func CacheDisabled() *RequestCacheOptions
CacheDisabled returns a RequestCacheOptions with caching disabled
func CacheEnabled ¶ added in v0.6.7
func CacheEnabled(ttl time.Duration) *RequestCacheOptions
CacheEnabled returns a RequestCacheOptions with caching enabled
type RequestInterceptors ¶ added in v0.3.0
type RequestOptions ¶ added in v0.2.1
type RequestOptions struct {
Method string
URL string
BaseURL string
Params map[string]string
Body interface{}
Headers map[string]string
Timeout int
Auth *Auth
ResponseType string
ResponseEncoding string
MaxRedirects int
MaxContentLength int64
MaxBodyLength int64
Decompress bool
ValidateStatus func(int) bool
InterceptorOptions InterceptorOptions
Proxy *Proxy
OnUploadProgress func(bytesRead, totalBytes int64)
OnDownloadProgress func(bytesRead, totalBytes int64)
LogLevel LogLevel
Cache *RequestCacheOptions
}
type Response ¶
func Patch ¶
func Patch(urlStr string, body interface{}, options ...*RequestOptions) (*Response, error)
type ResponseInterceptors ¶ added in v0.3.0
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
caching
command
|
|
|
download
command
|
|
|
interceptor
command
|
|
|
promise_style
command
|
|
|
request_style
command
|
|
|
simple_style
command
|