http

package
v1.1.17 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2022 License: Unlicense Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Error

type Error struct {
	*utils.GError
	StatusCode int
}

Error describes an error returned by the Polygon client

type IWebClientOption

type IWebClientOption interface {
	Apply(*WebClient)
}

IWebClientOption defines the functionality that will allow the behavior of a WebClient to be modified at construction

type WebClient

type WebClient struct {
	// contains filtered or unexported fields
}

WebClient defines an HTTP client that can be used to handle typical JSON responses from an API

func NewWebClient

func NewWebClient(logger *utils.Logger, opts ...IWebClientOption) *WebClient

NewWebClient creates a new connection to an API

func WithClient

func WithClient(client *http.Client, logger *utils.Logger, opts ...IWebClientOption) *WebClient

WithClient creates a new connection to the API with a given HTTP client

func (*WebClient) Deserialize

func (client *WebClient) Deserialize(body []byte, obj interface{}) error

Deserialize extracts the respone body JSON into the object provided

func (*WebClient) DoRequest

func (client *WebClient) DoRequest(request *http.Request) (*http.Response, error)

DoRequest attempts an HTTP request and returns the HTTP response

func (*WebClient) FromHTTPResponse

func (client *WebClient) FromHTTPResponse(err error, resp *http.Response) *Error

FromHTTPResponse creates a new client error from an HTTP response, and an inner error

func (*WebClient) GetBody

func (client *WebClient) GetBody(reader io.ReadCloser) ([]byte, error)

GetBody reads the body from an HTTP response

func (*WebClient) GetData

func (client *WebClient) GetData(request *http.Request, obj interface{}) error

GetData attempts to run an HTTP request against an endpoint and deserialize the respone into the object provided

func (*WebClient) NewClientError

func (client *WebClient) NewClientError(original error, message string, args ...interface{}) *Error

NewClientError creates a new client error from the original error, an erorr message and associated format arguments

type WithBackoffEnd

type WithBackoffEnd time.Duration

WithBackoffEnd allows the user to set the ending time to use when backing off from an API error that should be retried

func (WithBackoffEnd) Apply

func (w WithBackoffEnd) Apply(client *WebClient)

Apply modifies the WebClient so that it has the end interval defined by this object

type WithBackoffMaxElapsed

type WithBackoffMaxElapsed time.Duration

WithBackoffMaxElapsed allows the user to set the maximum time that should be allowed when the API returns an error that should be retried

func (WithBackoffMaxElapsed) Apply

func (w WithBackoffMaxElapsed) Apply(client *WebClient)

Apply modifies the WebClient so that it has the maximum interval defined by this object

type WithBackoffStart

type WithBackoffStart time.Duration

WithBackoffStart allows the user to set the starting time to use when backing off from an API error that should be retried

func (WithBackoffStart) Apply

func (w WithBackoffStart) Apply(client *WebClient)

Apply modifies the WebClient so that it has the start interval defined by this object

type WithErrorHandler

type WithErrorHandler func(*WebClient, []byte) string

WithErrorHandler allows the user to set the error handler function that is called when an API request returns a bad response

func (WithErrorHandler) Apply

func (w WithErrorHandler) Apply(client *WebClient)

Apply modifies the WebClient so that it has the error handler defined by this object

type WithRetryCodes

type WithRetryCodes []int

WithRetryCodes allows the user to define the HTTP status codes that would trigger a retry of the API endpoint rather than generating an error

func (WithRetryCodes) Apply

func (w WithRetryCodes) Apply(client *WebClient)

Apply modifies the WebClient so that it has the retry codes defined by this object

Jump to

Keyboard shortcuts

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