httpclient

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2022 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnauthorized        = errors.New("unauthorized")
	ErrForbidden           = errors.New("forbidden")
	ErrNotFound            = errors.New("not found")
	ErrMethodNotAllowed    = errors.New("method not allowed")
	ErrTooManyRequests     = errors.New("too many requests")
	ErrInternalServerError = errors.New("internal server error")
	ErrServiceUnavailable  = errors.New("service unavailable")
	ErrRecoveryInitiated   = errors.New("try again later")
)

Errors that are returned by the API.

Functions

This section is empty.

Types

type BadRequestError

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

BadRequestError holds list of errors from http response that represent invalid data submitted by the user.

func NewBadRequestError

func NewBadRequestError(errors ...string) (err *BadRequestError)

NewBadRequestError constructs a new BadRequestError with provided errors.

func (*BadRequestError) Error

func (e *BadRequestError) Error() (s string)

func (*BadRequestError) Errors

func (e *BadRequestError) Errors() (errs []string)

Errors returns a list of error messages.

type Client

type Client struct {
	Host       string
	HTTPClient *http.Client
}

func NewClient

func NewClient(u *url.URL, o *ClientOptions) (c *Client, err error)

func (*Client) Request

func (c *Client) Request(ctx context.Context, method, path string, body io.Reader, v interface{}) (err error)

request handles the HTTP request response cycle.

func (*Client) RequestData

func (c *Client) RequestData(ctx context.Context, method, path string, body io.Reader) (resp io.ReadCloser, err error)

requestData handles the HTTP request response cycle.

func (*Client) RequestJSON

func (c *Client) RequestJSON(ctx context.Context, method, path string, body, v interface{}) (err error)

requestJSON handles the HTTP request response cycle. It JSON encodes the request body, creates an HTTP request with provided method on a path with required headers and decodes request body if the v argument is not nil and content type is application/json.

func (*Client) RequestWithHeader

func (c *Client) RequestWithHeader(ctx context.Context, method, path string, header http.Header, body io.Reader, v interface{}) (err error)

requestWithHeader handles the HTTP request response cycle.

func (*Client) RequestWithResponseHeader

func (c *Client) RequestWithResponseHeader(ctx context.Context, method, path string, body io.Reader) (*http.Response, error)

type ClientOptions

type ClientOptions struct {
	HTTPClient *http.Client
}

Jump to

Keyboard shortcuts

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