httputil

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2021 License: MIT Imports: 12 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 {
	ClientDriver

	// AccessToken is the token to attach to the request.
	AccessToken string
	// HomeServer is the host part of the homeserver and is treated as the host
	// for all requests.
	HomeServer string
	// HomeServerScheme is the scheme to talk to homeserver on.
	// It is https most of the time.
	HomeServerScheme string
	// contains filtered or unexported fields
}

Client is a HTTP client that is Matrix API-aware.

func NewClient

func NewClient() Client

NewClient creates a new Client that uses the default HTTP client.

func NewCustomClient

func NewCustomClient(d ClientDriver) Client

NewCustomClient creates a new Client that uses the provided ClientDriver.

func (*Client) FullRoute added in v0.3.0

func (c *Client) FullRoute(route string) string

FullRoute creates the full route from the provided route.

func (*Client) Request

func (c *Client) Request(method, route string, to interface{}, mods ...Modifier) error

Request makes the request and returns the result.

It may return any HTTP request errors or a matrix.HTTPError which may possibly wrap a matrix.APIError.

func (Client) WithContext added in v0.2.0

func (c Client) WithContext(ctx context.Context) Client

WithContext creates a copy of Client that uses the provided context during request creation.

type ClientDriver

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

ClientDriver represents a HTTP client that can make requests to the endpoint.

type Modifier

type Modifier func(c *Client, req *http.Request)

Modifier modifies the Request before it's sent out to add extra info.

func WithBody

func WithBody(body io.ReadCloser) Modifier

WithBody attaches a io.ReadCloser to the request.

func WithFullQuery

func WithFullQuery(query map[string][]string) Modifier

WithFullQuery attaches one-to-many queries to the request.

func WithHeader added in v0.2.0

func WithHeader(header map[string][]string) Modifier

WithHeader attaches the provided headers to the request.

func WithJSONBody added in v0.2.0

func WithJSONBody(body interface{}) Modifier

WithJSONBody attaches a JSON body to the request.

func WithQuery

func WithQuery(rawQueries map[string]string) Modifier

WithQuery attaches one-to-one queries to the request. It is provided as a helper function that calls WithFullQuery.

func WithToken

func WithToken() Modifier

WithToken attaches the AccessToken to the request. It should be included with requests that require authentication.

Jump to

Keyboard shortcuts

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