Documentation
¶
Index ¶
- Variables
- func IsFatalError(err error) bool
- func IsRetryableError(err error) bool
- type CircuitBreaker
- type CircuitState
- type Client
- type Config
- type HTTPError
- type RateLimiter
- type SessionManager
- func (sm *SessionManager) AddCustomCookie(name, value string) error
- func (sm *SessionManager) ClearAllCookies() error
- func (sm *SessionManager) GetCurrentSessionIndex() int
- func (sm *SessionManager) GetNextSession() *http.Client
- func (sm *SessionManager) GetSessionCount() int
- func (sm *SessionManager) GetSessionStats() map[string]interface{}
- func (sm *SessionManager) InitializeSessions() error
- func (sm *SessionManager) RotateSession()
- type TransportError
Constants ¶
This section is empty.
Variables ¶
var ( ErrTooManyRequests = errors.New("too many requests (429)") ErrDecode = errors.New("decode error") ErrClientConfig = errors.New("client configuration error") ErrRateLimited = errors.New("rate limited") ErrCircuitOpen = errors.New("circuit breaker is open") ErrTimeout = errors.New("request timeout") ErrContextCanceled = errors.New("context canceled") )
Error types for HTTP operations
Functions ¶
func IsFatalError ¶
IsFatalError checks if an error is fatal and should not be retried
func IsRetryableError ¶
IsRetryableError checks if an error should trigger a retry
Types ¶
type CircuitBreaker ¶
type CircuitBreaker struct {
// contains filtered or unexported fields
}
CircuitBreaker implements a circuit breaker pattern
func NewCircuitBreaker ¶
func NewCircuitBreaker(window time.Duration, failureThreshold int, resetTimeout time.Duration) *CircuitBreaker
NewCircuitBreaker creates a new circuit breaker
func (*CircuitBreaker) Allow ¶
func (cb *CircuitBreaker) Allow() bool
Allow checks if the circuit breaker allows the request
func (*CircuitBreaker) Failures ¶
func (cb *CircuitBreaker) Failures() int
Failures returns the current failure count (for testing)
func (*CircuitBreaker) RecordFailure ¶
func (cb *CircuitBreaker) RecordFailure()
RecordFailure records a failed request
func (*CircuitBreaker) RecordSuccess ¶
func (cb *CircuitBreaker) RecordSuccess()
RecordSuccess records a successful request
func (*CircuitBreaker) State ¶
func (cb *CircuitBreaker) State() CircuitState
State returns the current state of the circuit breaker
type CircuitState ¶
type CircuitState int
CircuitState represents the state of the circuit breaker
const ( StateClosed CircuitState = iota StateOpen StateHalfOpen )
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client provides a robust HTTP client with retry, backoff, rate limiting, circuit breaker, and session rotation
func (*Client) Do ¶
Do executes an HTTP request with retry, backoff, rate limiting, and circuit breaker
func (*Client) GetSessionStats ¶
GetSessionStats returns session usage statistics
type Config ¶
type Config struct {
BaseURL string
Timeout time.Duration
IdleTimeout time.Duration
MaxConnsPerHost int
MaxAttempts int
BackoffBaseMs int
BackoffJitterMs int
MaxDelayMs int
QPS float64
Burst int
CircuitWindow time.Duration
FailureThreshold int
ResetTimeout time.Duration
UserAgent string
EnableSessionRotation bool
NumSessions int
}
Config holds HTTP client configuration
func DefaultConfig ¶
func DefaultConfig() *Config
DefaultConfig returns a sensible default configuration
func SessionRotationConfig ¶
func SessionRotationConfig() *Config
SessionRotationConfig returns a configuration optimized for session rotation
type HTTPError ¶
HTTPError wraps HTTP status errors with additional context
func NewHTTPError ¶
NewHTTPError creates a new HTTP error
type RateLimiter ¶
type RateLimiter struct {
// contains filtered or unexported fields
}
RateLimiter implements a token bucket rate limiter
func NewRateLimiter ¶
func NewRateLimiter(qps, burst int) *RateLimiter
NewRateLimiter creates a new rate limiter
type SessionManager ¶
type SessionManager struct {
// contains filtered or unexported fields
}
SessionManager manages multiple HTTP sessions with cookie rotation This helps avoid rate limiting by rotating between different sessions
func NewSessionManager ¶
func NewSessionManager(baseURL string, numSessions int) *SessionManager
NewSessionManager creates a new session manager with multiple sessions
func (*SessionManager) AddCustomCookie ¶
func (sm *SessionManager) AddCustomCookie(name, value string) error
AddCustomCookie adds a custom cookie to all sessions
func (*SessionManager) ClearAllCookies ¶
func (sm *SessionManager) ClearAllCookies() error
ClearAllCookies clears all cookies from all sessions
func (*SessionManager) GetCurrentSessionIndex ¶
func (sm *SessionManager) GetCurrentSessionIndex() int
GetCurrentSessionIndex returns the current session index
func (*SessionManager) GetNextSession ¶
func (sm *SessionManager) GetNextSession() *http.Client
GetNextSession returns the next session in rotation
func (*SessionManager) GetSessionCount ¶
func (sm *SessionManager) GetSessionCount() int
GetSessionCount returns the number of sessions
func (*SessionManager) GetSessionStats ¶
func (sm *SessionManager) GetSessionStats() map[string]interface{}
GetSessionStats returns statistics about session usage
func (*SessionManager) InitializeSessions ¶
func (sm *SessionManager) InitializeSessions() error
InitializeSessions initializes all sessions by making a request to get initial cookies
func (*SessionManager) RotateSession ¶
func (sm *SessionManager) RotateSession()
RotateSession manually rotates to the next session
type TransportError ¶
type TransportError struct {
Err error
}
TransportError represents a network transport error
func NewTransportError ¶
func NewTransportError(err error) *TransportError
NewTransportError creates a new transport error
func (*TransportError) Error ¶
func (e *TransportError) Error() string
func (*TransportError) Unwrap ¶
func (e *TransportError) Unwrap() error