request

package
v0.0.0-...-7f71e2c Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2024 License: BSD-3-Clause Imports: 17 Imported by: 14

Documentation

Index

Constants

View Source
const (
	BASE_URL             = "https://discord.com/api/v10"
	AuditLogReasonHeader = "X-Audit-Log-Reason"
)

Variables

View Source
var Client = http.Client{
	Transport: &http.Transport{
		TLSHandshakeTimeout: time.Second * 3,
	},
	Timeout: time.Second * 3,
}

TODO: Allow users to specify custom timeouts

Functions

func EncodeMultipartFormData

func EncodeMultipartFormData(payload MultipartPayload) ([]byte, string, error)

func RegisterHook

func RegisterHook(hook func(string, *http.Request))

Types

type ApiV8Error

type ApiV8Error struct {
	Code    interface{} // Can be int or string
	Errors  []FieldError
	Message string
}

func (*ApiV8Error) UnmarshalJSON

func (e *ApiV8Error) UnmarshalJSON(data []byte) error

type Attachment

type Attachment struct {
	Id          int    `json:"id"`
	Description string `json:"description,omitempty"`
	FileName    string `json:"filename"`
	File        File   `json:"-"`
}

type ContentType

type ContentType string
const (
	ApplicationJson           ContentType = "application/json"
	ApplicationFormUrlEncoded ContentType = "application/x-www-form-urlencoded"
	MultipartFormData         ContentType = "multipart/form-data"
	ImageJpeg                 ContentType = "image/jpeg"
	ImagePng                  ContentType = "image/png"
	ImageGif                  ContentType = "image/gif"
	Nil                       ContentType = ""
)

type Endpoint

type Endpoint struct {
	RequestType       RequestType
	ContentType       ContentType
	Endpoint          string
	Route             ratelimit.Route
	RateLimiter       *ratelimit.Ratelimiter
	AdditionalHeaders map[string]string
}

func (*Endpoint) Request

func (e *Endpoint) Request(ctx context.Context, token string, body any, response any) (error, *ResponseWithContent)

type FieldError

type FieldError struct {
	FieldName string      `json:"-"`
	Code      interface{} `json:"code"` // Can be int or string
	Message   string      `json:"message"`
}

func (FieldError) Error

func (e FieldError) Error() string

type File

type File struct {
	ContentType string
	Reader      io.Reader
}

type MultipartPayload

type MultipartPayload interface {
	GetAttachments() []Attachment
}

type RequestType

type RequestType string
const (
	GET    RequestType = "GET"
	POST   RequestType = "POST"
	PATCH  RequestType = "PATCH"
	PUT    RequestType = "PUT"
	DELETE RequestType = "DELETE"
)

type ResponseWithContent

type ResponseWithContent struct {
	*http.Response
	Content []byte
}

type RestError

type RestError struct {
	StatusCode int
	ApiError   ApiV8Error
	Url        string
	Raw        []byte
}

func (RestError) Error

func (r RestError) Error() string

func (*RestError) IsClientError

func (r *RestError) IsClientError() bool

func (*RestError) IsServerError

func (r *RestError) IsServerError() bool

Jump to

Keyboard shortcuts

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