Documentation
¶
Overview ¶
Package client provides a base client implementation for interacting with EdgeCast CDN APIs. Configuration and authentication types are also provided.
Index ¶
- func ExponentialJitterBackoff(min, max time.Duration, attemptNum int, resp *http.Response) time.Duration
- type Client
- func (c Client) BuildRequest(method, path string, body interface{}) (*retryablehttp.Request, error)
- func (c *Client) SendRequest(req *retryablehttp.Request, parsedResponse interface{}) (*http.Response, error)
- func (c *Client) SendRequestWithStringResponse(req *retryablehttp.Request) (*string, error)
- type ClientConfig
- type LiteralResponse
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExponentialJitterBackoff ¶ added in v0.1.9
func ExponentialJitterBackoff( min, max time.Duration, attemptNum int, resp *http.Response, ) time.Duration
ExponentialJitterBackoff calculates exponential backoff, with jitter, based on the attempt number and limited by the provided minimum and maximum durations.
It also tries to parse Retry-After response header when a http.StatusTooManyRequests (HTTP Code 429) is found in the resp parameter. Hence it will return the number of seconds the server states it may be ready to process more requests from this client.
Types ¶
type Client ¶
type Client struct {
// Config holds the configuration values for this client
Config ClientConfig
// Internal HTTP client
HTTPClient *retryablehttp.Client
}
Client is the primary means for services to interact with the EdgeCast API
func NewClient ¶
func NewClient(config ClientConfig) Client
Creates a new client pointing to EdgeCast APIs
func (Client) BuildRequest ¶
func (c Client) BuildRequest( method, path string, body interface{}, ) (*retryablehttp.Request, error)
BuildRequest creates a new Request for the Edgecast API, adding appropriate headers
func (*Client) SendRequest ¶
func (c *Client) SendRequest( req *retryablehttp.Request, parsedResponse interface{}, ) (*http.Response, error)
SendRequest sends an HTTP request and, if applicable, sets the response to parsedResponse
func (*Client) SendRequestWithStringResponse ¶
func (c *Client) SendRequestWithStringResponse( req *retryablehttp.Request, ) (*string, error)
SendRequest sends an HTTP request and, if applicable, sets the response to parsedResponse
type ClientConfig ¶
type ClientConfig struct {
// Generates Authorization Header values for HTTP requests
AuthProvider auth.AuthorizationProvider
// APIURL contains the base URL for the target API
BaseAPIURL url.URL
// The User Agent for outgoing HTTP requests
UserAgent string
Logger logging.Logger
RetryWaitMin *time.Duration
RetryWaitMax *time.Duration
RetryMax *int
}
ClientConfig provides configuration for the base client
type LiteralResponse ¶
type LiteralResponse struct {
Value interface{}
}
LiteralResponse is used for unmarshaling response data that is in an unrecognized format