carry

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2024 License: MIT Imports: 12 Imported by: 4

README

🗃️ Carry

Go Reference Go Report Card Taylor Swift Volkswagen License

carry is a Go HTTP client library that provides a simple and clean API for interacting with RESTful APIs. It had been specifically created to support HMAC authentication.

Installation

go get github.com/zeiss/carry

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BodyProvider

type BodyProvider interface {
	// ContentType returns the Content-Type of the body.
	ContentType() string
	// Body returns the io.Reader body.
	Body() (io.Reader, error)
}

BodyProvider provides Body content for http.Request attachment.

type Client

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

Client is an HTTP Request builder and sender.

func New

func New() *Client

New returns a new Client with an http DefaultClient.

func (*Client) Add

func (s *Client) Add(key, value string) *Client

Add adds the key, value pair in Headers, appending values for existing keys to the key's values. Header keys are canonicalized.

func (*Client) Base

func (s *Client) Base(rawURL string) *Client

Base sets the rawURL of the Client. The rawURL is resolved to an absolute

func (*Client) Body

func (s *Client) Body(body io.Reader) *Client

Body sets the Client's body. The body is used on new requests (see Request()).

func (*Client) BodyForm

func (s *Client) BodyForm(bodyForm interface{}) *Client

BodyForm sets the Client's bodyForm. The value pointed to by the bodyForm

func (*Client) BodyJSON

func (s *Client) BodyJSON(bodyJSON interface{}) *Client

BodyJSON sets the Client's bodyJSON. The value pointed to by the bodyJSON

func (*Client) BodyProvider

func (s *Client) BodyProvider(body BodyProvider) *Client

BodyProvider sets the Client's body provider.

func (*Client) Client

func (s *Client) Client(httpClient *http.Client) *Client

Client sets the http Client used to do requests. If a nil client is given, the http.DefaultClient will be used.

func (*Client) Connect

func (s *Client) Connect(pathURL string) *Client

Connect sets the Client method to CONNECT and sets the given pathURL.

func (*Client) Delete

func (s *Client) Delete(pathURL string) *Client

Delete sets the Client method to DELETE and sets the given pathURL.

func (*Client) Do

func (s *Client) Do(req *http.Request, successV, failureV interface{}) (*http.Response, error)

Do sends an HTTP request and returns an HTTP response, following policy

func (*Client) Doer

func (s *Client) Doer(doer Doer) *Client

Doer sets the custom Doer implementation used to do requests. If a nil client is given, the http.DefaultClient will be used.

func (*Client) Get

func (s *Client) Get(pathURL string) *Client

Get sets the Client method to GET and sets the given pathURL.

func (*Client) Head

func (s *Client) Head(pathURL string) *Client

Head sets the Client method to HEAD and sets the given pathURL.

func (*Client) New

func (s *Client) New() *Client

New returns a copy of a Client for creating a new Client with properties from a parent Client.

func (*Client) Options

func (s *Client) Options(pathURL string) *Client

Options sets the Client method to OPTIONS and sets the given pathURL.

func (*Client) Patch

func (s *Client) Patch(pathURL string) *Client

Patch sets the Client method to PATCH and sets the given pathURL.

func (*Client) Path

func (s *Client) Path(path string) *Client

Path extends the rawURL with the given path by resolving the reference to an absolute URL. If parsing errors occur, the rawURL is left unmodified.

func (*Client) Post

func (s *Client) Post(pathURL string) *Client

Post sets the Client method to POST and sets the given pathURL.

func (*Client) Put

func (s *Client) Put(pathURL string) *Client

Put sets the Client method to PUT and sets the given pathURL.

func (*Client) QueryStruct

func (s *Client) QueryStruct(queryStruct interface{}) *Client

QueryStruct appends the queryStruct to the Client's queryStructs. The

func (*Client) Receive

func (s *Client) Receive(ctx context.Context, successV, failureV interface{}) (*http.Response, error)

Receive creates a new HTTP request and returns the response. Success responses

func (*Client) ReceiveSuccess

func (s *Client) ReceiveSuccess(ctx context.Context, successV interface{}) (*http.Response, error)

ReceiveSuccess creates a new HTTP request and returns the response. Success

func (*Client) Request

func (s *Client) Request(ctx context.Context) (*http.Request, error)

Request returns a new http.Request created from the Client's properties.

func (*Client) ResponseDecoder

func (s *Client) ResponseDecoder(decoder ResponseDecoder) *Client

ResponseDecoder sets the Client's response decoder.

func (*Client) Set

func (s *Client) Set(key, value string) *Client

Set sets the key, value pair in Headers, replacing existing values associated with key. Header keys are canonicalized.

func (*Client) SetBasicAuth

func (s *Client) SetBasicAuth(username, password string) *Client

SetBasicAuth sets the Authorization header to use HTTP Basic Authentication

func (*Client) SignProvider

func (s *Client) SignProvider(signer SignerProvider) *Client

SignProvider sets the Client's SignerProvider.

func (*Client) Trace

func (s *Client) Trace(pathURL string) *Client

Trace sets the Client method to TRACE and sets the given pathURL.

type Doer

type Doer interface {
	Do(req *http.Request) (*http.Response, error)
}

Doer executes http requests. It is implemented by *http.Client. You can wrap *http.Client with layers of Doers to form a stack of client-side middleware.

type HMACSigner

type HMACSigner struct {
	Key string
}

HMACSigner signs requests with an HMAC signature.

func NewHMacSigner

func NewHMacSigner(key string) *HMACSigner

NewHMacSigner returns a new HMACSigner.

func (HMACSigner) Sign

func (s HMACSigner) Sign(req *http.Request) error

Sign signs the request with an HMAC signature.

type ResponseDecoder

type ResponseDecoder interface {
	// Decode decodes the response into the value pointed to by v.
	Decode(resp *http.Response, v interface{}) error
}

ResponseDecoder decodes http responses into struct values.

type SignerProvider

type SignerProvider interface {
	Sign(req *http.Request) error
}

SignProvid provides a Signer for requests.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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