common

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2023 License: Apache-2.0 Imports: 12 Imported by: 4

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 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