opts

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 17, 2022 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package opts allows us to customise the settings to use with a payment provider API

the settings defined here are platform agnostic and can be applied to all providers. applying settings in this fashion also allows us to set reasonable defaults in tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIOption

type APIOption interface {
	// contains filtered or unexported methods
}

APIOption configures how we set up the API.

func WithBackoff

func WithBackoff(b backoff.Backoff) APIOption

WithBackoff overrides the backoff strategy to in between retries.

func WithCredentials

func WithCredentials(c auth.Credentials) APIOption

WithCredentials overrides the credentials to use.

func WithEncoder

func WithEncoder(f format.Encoder) APIOption

WithEncoder overrides the request and response encoder for the client.

func WithHTTPClient

func WithHTTPClient(h *http.Client) APIOption

WithHTTPClient sets the http.Client to use for each request. this can be used to finely tweak TLS settings or add a custom http.RoundTripper

func WithLanguage

func WithLanguage(l language.Tag) APIOption

WithLanguage overrides the language to use.

func WithLogger

func WithLogger(l log.Logger) APIOption

WithLogger overrides the logger to use.

func WithMaxNetworkRetries

func WithMaxNetworkRetries(n int64) APIOption

WithMaxNetworkRetries overrides the max number of retries to attempt.

func WithTimeout

func WithTimeout(t time.Duration) APIOption

WithTimeout overrides the per-request timeout.

func WithUserAgent

func WithUserAgent(ua string) APIOption

WithUserAgent updates the API options with the supplied user-agent.

type Options

type Options struct {
	HTTPClient        *http.Client     // HTTPClient is the http client to use.
	MaxNetworkRetries int64            // MaxNetworkRetries the maximum number of retries on API failure.
	Encoder           format.Encoder   // Encoder is the encoder to use to encode / decode requests and responses.
	UserAgent         string           // UserAgent the user agent to send with each request.
	Credentials       auth.Credentials // Credentials the method in which to authenticate if applicable.
	Backoff           backoff.Backoff  // Backoff allows us to customise the function to determine the backoff for retries.
	Logger            log.Logger       // Logger the logger to use when performing requests.
	Language          language.Tag     // Language language used to set the Accept-Language header.

	// Timeout defines the timeout which is applied to each request, a timeout of zero
	// represents no timeout is applied.
	Timeout time.Duration
}

Options defines the options to use with the API.

func Apply

func Apply(opts ...APIOption) *Options

Apply applies the options and returns the generated options.

Jump to

Keyboard shortcuts

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