Documentation
¶
Index ¶
- Constants
- Variables
- func Bytes(resp *req.Response, err error) ([]byte, error)
- func Stream(resp *req.Response, err error) (io.ReadCloser, error)
- func String(resp *req.Response, err error) (string, error)
- type Client
- func (c *Client) AR(serviceLabel string) *req.Request
- func (c *Client) IR(label string) *req.Request
- func (c *Client) R() *req.Request
- func (c *Client) RegisterAuth(serviceLabel string, identityReader cred.IdentityReader, ...) *Client
- func (c *Client) RegisterInterceptor(label string, interceptor Interceptor) *Client
- func (c *Client) RegisterToken(serviceLabel string, token string) *Client
- func (c *Client) UnregisterAuth(serviceLabel string)
- func (c *Client) UnregisterInterceptor(label string)
- type Config
- type Impersonation
- type Interceptor
- type Options
- type RefreshTokenFunc
Constants ¶
const ( // JsonApplicationContentType - JSON content type header JsonApplicationContentType string = "application/json" // FormUrlEncodedApplicationContentType - x-www-form-urlencoded content type header FormUrlEncodedApplicationContentType string = "application/x-www-form-urlencoded" )
Variables ¶
var ( ErrResponseNil = errors.New("response is nil") ErrResponseBodyNil = errors.New("response body is nil") )
var ( ErrInterceptorNotFound = fmt.Errorf("interceptor not found") ErrMaxRetriesExceeded = fmt.Errorf("max interceptor retries exceeded") )
Functions ¶
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client wraps req.Client and provides both authenticated and normal requests
func (*Client) RegisterAuth ¶
func (c *Client) RegisterAuth(serviceLabel string, identityReader cred.IdentityReader, refreshFunc func(*Client, cred.Identity) (string, error)) *Client
RegisterAuth registers an authentication provider using a refreshable token with the given label
func (*Client) RegisterInterceptor ¶
func (c *Client) RegisterInterceptor(label string, interceptor Interceptor) *Client
RegisterInterceptor registers an interceptor with the given label
func (*Client) RegisterToken ¶
RegisterToken registers an authentication provider using a fixed token with the given label
func (*Client) UnregisterAuth ¶
UnregisterAuth unregisters an authentication provider with the given label
func (*Client) UnregisterInterceptor ¶
UnregisterInterceptor unregisters an interceptor with the given label
type Config ¶
Config is a function that configures the underlying req.Client (for advanced use cases)
type Impersonation ¶
type Impersonation byte
const ( None Impersonation = iota Chrome Firefox Safari )
type Interceptor ¶
type Interceptor interface {
// ShouldIntercept returns true if this response/error should trigger recovery.
// Both resp and err are provided so status codes can be checked (e.g. 429, 401)
// even when they're wrapped as errors by the retry logic.
ShouldIntercept(resp *req.Response, err error) bool
// Recover performs the recovery action (refresh cookies, re-login, etc.)
// This is called when ShouldIntercept returns true.
// The implementation should store any state it needs for Apply.
Recover(client *Client, resp *req.Response) error
// Apply applies the current state to the request (set cookies, headers, etc.)
// This is called before every request attempt to apply stored state.
Apply(r *req.Request) *req.Request
// MaxRetries returns the maximum number of recovery attempts per request.
// Return 0 or negative to use the default (1).
MaxRetries() int
}
Interceptor handles response interception and recovery.
Thread safety: Implementations do NOT need to handle synchronization. The interceptor system guarantees that Recover and Apply are never called concurrently.
Thundering herd prevention: When multiple concurrent requests trigger recovery, only one Recover call executes. Other goroutines waiting will skip recovery and use the newly recovered state.
type Options ¶
type Options struct {
RetryCount int
MinBackoff time.Duration
MaxBackoff time.Duration
Timeout time.Duration
AuthRefreshBuffer time.Duration
EnableHttp3 bool
AutoDecompress bool
AutoDecode bool
DisableKeepAlives bool
Impersonation Impersonation
}
Options settings to configure the retryable HTTP client