client

package
v0.1.15 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 12, 2022 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package client provides a base client implementation for interacting with EdgeCast CDN APIs. Configuration and authentication types are also provided.

Index

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) PrepareRequest added in v0.1.12

func (c Client) PrepareRequest(
	method, path string,
	body interface{},
	queryParams map[string]string,
	pathParams map[string]string,
) (*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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL