client

package
v0.20230201.1144511 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2023 License: MPL-2.0 Imports: 18 Imported by: 10,795

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RequestRetryAll

func RequestRetryAll(retryFuncs ...RequestRetryFunc) func(resp *http.Response, o *odata.OData) (bool, error)

RequestRetryAll wraps multiple RequestRetryFuncs and calls them in turn, only returning true if all funcs return true

func RequestRetryAny

func RequestRetryAny(retryFuncs ...RequestRetryFunc) func(resp *http.Response, o *odata.OData) (bool, error)

RequestRetryAny wraps multiple RequestRetryFuncs and calls them in turn, returning true if any func returns true

func RetryOn404ConsistencyFailureFunc

func RetryOn404ConsistencyFailureFunc(resp *http.Response, _ *odata.OData) (bool, error)

RetryOn404ConsistencyFailureFunc can be used to retry a request when a 404 response is received

func RetryableErrorHandler

func RetryableErrorHandler(resp *http.Response, _ error, _ int) (*http.Response, error)

RetryableErrorHandler ensures that the response is returned after exhausting retries for a request We mustn't return an error here, or net/http will not return the response

Types

type BaseClient

type BaseClient interface {
	Execute(ctx context.Context, req *Request) (*Response, error)
	ExecutePaged(ctx context.Context, req *Request) (*Response, error)
	NewRequest(ctx context.Context, input RequestOptions) (*Request, error)
}

type Client

type Client struct {
	// BaseUri is the base endpoint for this API.
	BaseUri string

	// UserAgent is the HTTP user agent string to send in requests.
	UserAgent string

	// CorrelationId is a custom correlation ID which can be added to requests for tracing purposes
	CorrelationId string

	// Authorizer is anything that can provide an access token with which to authorize requests.
	Authorizer auth.Authorizer

	// DisableRetries prevents the client from reattempting failed requests (which it does to work around eventual consistency issues).
	// This does not impact handling of retries related to rate limiting, which are always performed.
	DisableRetries bool

	// RequestMiddlewares is a slice of functions that are called in order before a request is sent
	RequestMiddlewares *[]RequestMiddleware

	// ResponseMiddlewares is a slice of functions that are called in order before a response is parsed and returned
	ResponseMiddlewares *[]ResponseMiddleware
}

Client is a base client to be used by API-specific clients. It satisfies the BaseClient interface.

func NewClient

func NewClient(baseUri string, serviceName, apiVersion string) *Client

NewClient returns a new Client configured with sensible defaults

func (*Client) Execute

func (c *Client) Execute(ctx context.Context, req *Request) (*Response, error)

Execute is used by the package to send an HTTP request to the API

func (*Client) ExecutePaged

func (c *Client) ExecutePaged(ctx context.Context, req *Request) (*Response, error)

ExecutePaged automatically pages through the results of Execute

func (*Client) NewRequest

func (c *Client) NewRequest(ctx context.Context, input RequestOptions) (*Request, error)

NewRequest configures a new *Request

type Headers

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

func (Headers) Append

func (h Headers) Append(key, value string)

func (Headers) Headers

func (h Headers) Headers() http.Header

type Options

type Options interface {
	ToHeaders() *Headers
	ToOData() *odata.Query
	ToQuery() *QueryParams
}

type QueryParams

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

func QueryParamsFromValues

func QueryParamsFromValues(input map[string]string) *QueryParams

func (*QueryParams) Append

func (q *QueryParams) Append(key, value string)

func (*QueryParams) Values

func (q *QueryParams) Values() url.Values

type Request

type Request struct {
	RetryFunc        RequestRetryFunc
	ValidStatusCodes []int
	ValidStatusFunc  ValidStatusFunc

	Client BaseClient

	// Embed *http.Request so that we can send this to an *http.Client
	*http.Request
}

Request embeds *http.Request and adds useful metadata

func (*Request) Execute

func (r *Request) Execute(ctx context.Context) (*Response, error)

func (*Request) ExecutePaged

func (r *Request) ExecutePaged(ctx context.Context) (*Response, error)

func (*Request) IsIdempotent

func (r *Request) IsIdempotent() bool

func (*Request) Marshal

func (r *Request) Marshal(payload interface{}) error

type RequestMiddleware

type RequestMiddleware func(*http.Request) (*http.Request, error)

RequestMiddleware can manipulate or log a request before it is sent

type RequestOptions

type RequestOptions struct {
	ContentType         string
	ExpectedStatusCodes []int
	HttpMethod          string
	OptionsObject       Options
	Path                string
}

func (RequestOptions) Validate

func (ro RequestOptions) Validate() error

type RequestRetryFunc

type RequestRetryFunc func(*http.Response, *odata.OData) (bool, error)

RequestRetryFunc is a function that determines whether an HTTP request has failed due to eventual consistency and should be retried

type Response

type Response struct {
	OData *odata.OData

	// Embed *http.Response
	*http.Response
}

Response embeds *http.Response and adds useful methods

func (*Response) Unmarshal

func (r *Response) Unmarshal(model interface{}) error

type ResponseMiddleware

type ResponseMiddleware func(*http.Request, *http.Response) (*http.Response, error)

ResponseMiddleware can manipulate or log a response before it is parsed and returned

type ValidStatusFunc

type ValidStatusFunc func(*http.Response, *odata.OData) bool

ValidStatusFunc is a function that tests whether an HTTP response is considered valid for the particular request.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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