http

package
v1.6.7-0...-b28dd99 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	Client  *http.Client
	BaseURL *url.URL
}

Client represents an HTTP client.

func NewClient

func NewClient(uri, token string) (*Client, error)

NewClient returns new HTTP Client instance.

func (*Client) Do

func (c *Client) Do(ctx context.Context, method, path string, in, out interface{}) (*Response, error)

Do executes an HTTP request.

func (*Client) Req

func (c *Client) Req(ctx context.Context, in *Request, headers ...http.Header) (*Response, error)

Req sends an API request and returns the API response. The API reponse is JSON decoded and stored in the value, or returned as an error if an API error has occured.

type Error

type Error struct {
	Message string `json:"message"`
}

Error represents response error.

func (*Error) Error

func (e *Error) Error() string

type Request

type Request struct {
	Method string
	Path   string
	Header http.Header
	Body   io.Reader
}

Request defines an HTTP request.

type Response

type Response struct {
	Status int
	Header http.Header
	Body   io.ReadCloser
}

Response defines an HTTP response.

type TokenAuth

type TokenAuth struct {
	Base  http.RoundTripper
	Token string
}

TokenAuth is an http.RoundTripper that makes HTTP requests, wrapping a base RoundTripper and adding a bearer token authorization header.

func (*TokenAuth) RoundTrip

func (t *TokenAuth) RoundTrip(r *http.Request) (*http.Response, error)

RoundTrip adds the Authorization header to the request.

Jump to

Keyboard shortcuts

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