client

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2021 License: MIT Imports: 15 Imported by: 13

Documentation

Overview

Package client defines a Wireleap API client.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Refresh

func Refresh(req *http.Request) (err error)

Refresh refreshes the idempotency key (if applicable).

Types

type Client

type Client struct {
	*http.Client
	signer.Signer
	// contains filtered or unexported fields
}

Client is an API client type. It exposes the http.Client interface and it is safe for concurrent use by multiple goroutines. It also encapsulates the keypair used to access the API via its signer.Signer interface.

func New

func New(s signer.Signer, is ...interfaces.T) *Client

New creates a new API client using the given signer to sign API requests.

func NewMock

func NewMock(s signer.Signer, h http.Handler, is ...interfaces.T) (c *Client)

NewMock creates a new API client which uses a given handler for handling all requests.

func (*Client) Do

func (c *Client) Do(r *http.Request) (*http.Response, error)

func (*Client) NewRequest

func (c *Client) NewRequest(method string, url string, data interface{}) (*http.Request, error)

NewRequest is a convenience function for creating a new http.Request with a payload that's JSON-marshaled and signed.

func (*Client) ParseResponse added in v0.2.0

func (c *Client) ParseResponse(res *http.Response, dst interface{}, cs ...string) (err error)

ParseResponse extracts the JSON-encoded payload of a request response and checks for API errors. It is not a method of the Client type since it uses no Client-specific data. Therefore, while low-level, it can be called by code which does not use Client if needed.

func (*Client) Perform

func (c *Client) Perform(method string, url string, in interface{}, out interface{}, cs ...string) (err error)

Perform is a convenience function for creating a new request, performing it and parsing the JSON response into the receiving interface.

func (*Client) PerformRequestNoParse

func (c *Client) PerformRequestNoParse(req *http.Request, cs ...string) (res *http.Response, err error)

func (*Client) PerformRequestOnce

func (c *Client) PerformRequestOnce(req *http.Request, out interface{}, cs ...string) (err error)

func (*Client) SetInterfaces added in v0.2.0

func (c *Client) SetInterfaces(is ...interfaces.T)

func (*Client) SetTransport

func (c *Client) SetTransport(t http.RoundTripper)

Jump to

Keyboard shortcuts

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