rest

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Do

Do is used to request endpoints that do not need authentication. If you need more control over headers you send, use DoWithHeader directly.

func DoWithHeader

func DoWithHeader(ctx context.Context, e *endpoint.Endpoint, p *Payload, h http.Header) (*http.Response, error)

Do is used to request endpoints that do not need authentication. It is like DoWithHeader otherwise, except for rate limiting where it is more likely to result in 429's if abused.

func MultipartFromFiles

func MultipartFromFiles(payload MultipartPayload, files ...discord.File) ([]byte, string, error)

MultipartFromFiles generate a multipart body given a payload and some files. It returns the raw generated body along the content type of this body.

func ReasonHeader

func ReasonHeader(r string) http.Header

ReasonHeader returns an HTTP header with the Audit Log reason set to r.

Types

type Client

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

Client is a client that can make HTTP requests to Discord's REST API.

func NewClient

func NewClient(httpClient *http.Client, token, name string, logger log.Logger) *Client

NewClient returns a new REST Client.

func (*Client) Do

func (c *Client) Do(ctx context.Context, e *endpoint.Endpoint, p *Payload) (*http.Response, error)

Do is used to request Discord's HTTP endpoints. If you need more control over headers you send, use DoWithHeader directly.

func (*Client) DoWithHeader

func (c *Client) DoWithHeader(ctx context.Context, e *endpoint.Endpoint, p *Payload, h http.Header) (*http.Response, error)

DoWithHeader sends an HTTP request and returns the response given an endpoint an optional payload and some headers. It adds the required Authorization header, Content-Type based on the given payload and also sets the User-Agent. It also takes care of rate limiting, using the client's built in rate limiter.

type MultipartPayload

type MultipartPayload interface {
	Bytes() ([]byte, error)
}

MultipartPayload defines a payload that can be used in a multipart upload.

type Payload

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

Payload is a payload that is sent to Discord's REST API.

func CustomPayload

func CustomPayload(body []byte, contentType string) *Payload

CustomPayload creates a new custom payload from raw bytes and a given content type.

func JSONPayload

func JSONPayload(body json.RawMessage) *Payload

JSONPayload creates a new Payload from some raw JSON data.

Jump to

Keyboard shortcuts

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