request

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2021 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultHost is the the standard hostname, it is used in requests made by
	// the cli to the insprd/uidp services in the cluster
	DefaultHost = "inspr.com"
)

Variables

View Source
var (
	// DefaultErr is the error returned by the request's response when an
	// unexpected http.Status is provided and it doesn't have an error structure
	// in its response body.
	DefaultErr = ierrors.
		New("cannot retrieve error from server").
		InternalServer()
)

Functions

This section is empty.

Types

type Authenticator

type Authenticator interface {
	GetToken() ([]byte, error)
	SetToken([]byte) error
}

Authenticator is an interface to perform authentication via tokens

type Client

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

Client is a generic rest client

func NewClient

func NewClient() Client

NewClient returns an address of a empty Client

func NewJSONClient

func NewJSONClient(baseURL string) *Client

NewJSONClient returns a client for the given url with json encoding and decoding

func (Client) Authenticator

func (c Client) Authenticator(au Authenticator) Client

Authenticator adds the authentication interface implementation to the Client structure.

func (Client) BaseURL

func (c Client) BaseURL(url string) Client

BaseURL sets the base URL for the client structure

func (Client) Decoder

func (c Client) Decoder(decoder DecoderGenerator) Client

Decoder sets the decoder for the client structure

func (Client) Encoder

func (c Client) Encoder(encoder Encoder) Client

Encoder sets the encoder for the client structure

func (Client) HTTPClient

func (c Client) HTTPClient(client http.Client) Client

HTTPClient sets the http client for the client that is being built

func (Client) Header

func (c Client) Header(key, value string) Client

Header adds the value into the slice located by the key in the client's header map.

func (Client) Host added in v0.1.3

func (c Client) Host(value string) Client

Host sets the host for the client structure

func (Client) Pointer

func (c Client) Pointer() *Client

Pointer returns the address of an existing client

func (Client) Send

func (c Client) Send(ctx context.Context, route, method string, body, responsePtr interface{}) (err error)

Send sends a request to the url specified in instantiation, with the given route and method, using the encoder to encode the body and the decoder to decode the response into the responsePtr

func (Client) Token

func (c Client) Token(token []byte) Client

Token adds a token header with the format "Authentication: Bearer " + token on each request the client sends.

type Decoder

type Decoder interface{ Decode(interface{}) error }

Decoder is an interface that decodes a reader into an struct

func JSONDecoderGenerator

func JSONDecoderGenerator(r io.Reader) Decoder

JSONDecoderGenerator generates a decoder for json encoded requests

type DecoderGenerator

type DecoderGenerator func(r io.Reader) Decoder

DecoderGenerator creates a decoder for a given request

type Encoder

type Encoder func(interface{}) ([]byte, error)

Encoder encodes an interface into bytes

Jump to

Keyboard shortcuts

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