common

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: May 31, 2024 License: Apache-2.0 Imports: 15 Imported by: 5

Documentation

Index

Constants

View Source
const (
	PollPeriod  = 1 * time.Second
	MaxAttempts = 2
)

TODO(tho) make these two configurable

View Source
const (
	APIStatusFailed     = "failed"
	APIStatusSuccess    = "success"
	APIStatusProcessing = "processing"
	APIStatusComplete   = "complete"
)

Variables

This section is empty.

Functions

func CheckResponse added in v0.1.0

func CheckResponse(res *http.Response, expected ...int) error

func DecodeJSONBody

func DecodeJSONBody(res *http.Response, j interface{}) error

func ExtractLocation

func ExtractLocation(res *http.Response, base string) (string, error)

Extract Location header and resolve it to the supplied base (if non-empty)

func ResolveReference

func ResolveReference(baseURI, referenceURI string) (string, error)

Types

type Client

type Client struct {
	HTTPClient http.Client
	Auth       auth.IAuthenticator
}

Client holds configuration data associated with the HTTP(s) session, and a reference to an IAuthenticator that is used to provide Authorization headers for requests.

func NewClient

func NewClient(a auth.IAuthenticator) *Client

NewClient instantiates a new Client with a fixed 5s timeout. The client will use the provided IAuthenticator for requests, if it is not nil.

func NewClientWithTransport added in v0.3.0

func NewClientWithTransport(a auth.IAuthenticator, transport http.RoundTripper) *Client

NewClientWithTransport instantiates a new Client with the specified transport and a fixed 5s timeout. The client will use the provided IAuthenticator for requests, if it is not nil.

func NewInsecureTLSClient added in v0.3.0

func NewInsecureTLSClient(a auth.IAuthenticator) *Client

NewInsecureTLSClient instantiates a new Client with a transport configured to accept TLS connections without verifying certs and a fixed 5s timeout. The client will use the provided IAuthenticator for requests, if it is not nil.

func NewTLSClient added in v0.3.0

func NewTLSClient(a auth.IAuthenticator, certPaths []string) (*Client, error)

NewTLSClient instantiates a new Client with a fixed 5s timeout and transport configured with the system certificate pool as well as any certs provided. The client will use the provided IAuthenticator for requests, if it is not nil.

func NewTestingHTTPClient

func NewTestingHTTPClient(handler http.Handler) (cli *Client, closerFn func())

NewTestingHTTPClient creates an HTTP test server (with a configurable request handler), an API Client and connects them together. The API client and the server's shutdown switch are returned.

func (Client) DeleteResource

func (c Client) DeleteResource(uri string) error

func (Client) GetResource added in v0.1.0

func (c Client) GetResource(accept, uri string) (*http.Response, error)

func (Client) PostEmptyResource added in v0.1.0

func (c Client) PostEmptyResource(accept, uri string) (*http.Response, error)

func (Client) PostResource

func (c Client) PostResource(body []byte, ct, accept, uri string) (*http.Response, error)

type ProblemError added in v0.1.0

type ProblemError struct {
	problems.DefaultProblem
}

func (*ProblemError) Error added in v0.1.0

func (o *ProblemError) Error() string

Jump to

Keyboard shortcuts

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