Documentation ¶
Index ¶
- Constants
- func GlobalRateLimit(resp *http.Response) bool
- func GlobalRateLimitSafe(resp *http.Response, body *ratelimitBody) bool
- func RateLimited(resp *http.Response) bool
- func SupportsDiscordAPIVersion(version int) bool
- type Bucket
- type Client
- func (c *Client) Delete(req *Request) (resp *http.Response, body []byte, err error)
- func (c *Client) Get(req *Request) (resp *http.Response, body []byte, err error)
- func (c *Client) Patch(req *Request) (resp *http.Response, body []byte, err error)
- func (c *Client) Post(req *Request) (resp *http.Response, body []byte, err error)
- func (c *Client) Put(req *Request) (resp *http.Response, body []byte, err error)
- func (c *Client) RateLimiter() RateLimiter
- func (c *Client) Request(r *Request) (resp *http.Response, body []byte, err error)
- type Config
- type Deleter
- type Details
- type Getter
- type Patcher
- type Poster
- type Puter
- type RateLimit
- type RateLimitInfo
- type RateLimiter
- type Request
- type Requester
Constants ¶
View Source
const ( BaseURL = "https://discordapp.com/api" // Header AuthorizationFormat = "Bot %s" UserAgentFormat = "DiscordBot (%s, %s) %s" HTTPCodeRateLimit int = 429 ContentEncoding = "Content-Encoding" ContentType = "Content-Type" ContentTypeJSON = "application/json" GZIPCompression = "gzip" )
View Source
const ( XRateLimitLimit = "X-RateLimit-Limit" XRateLimitRemaining = "X-RateLimit-Remaining" XRateLimitReset = "X-RateLimit-Reset" // is converted from seconds to milliseconds! XRateLimitGlobal = "X-RateLimit-Global" RateLimitRetryAfter = "Retry-After" GlobalRateLimiterKey = "" )
Variables ¶
This section is empty.
Functions ¶
func GlobalRateLimit ¶
GlobalRateLimit assumes that there will always be a header entry when a global rate limit kicks in
func GlobalRateLimitSafe ¶
func RateLimited ¶
func SupportsDiscordAPIVersion ¶
SupportsDiscordAPIVersion check if a given discord api version is supported by this package.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func (*Client) RateLimiter ¶
func (c *Client) RateLimiter() RateLimiter
type RateLimit ¶
type RateLimit struct {
// contains filtered or unexported fields
}
RateLimit TODO: a bucket is created for every request. Might want to delete them after a while. seriously. `/users/1` has the same ratelimiter as `/users/2` but any major endpoint prefix does not: `/channels/1` != `/channels/2`
func NewRateLimit ¶
func NewRateLimit() *RateLimit
func (*RateLimit) RateLimitTimeout ¶
func (*RateLimit) RateLimited ¶
func (*RateLimit) UpdateRegisters ¶
TODO: rewrite
type RateLimitInfo ¶
type RateLimitInfo struct { Message string `json:"message"` RetryAfter int64 `json:"retry_after"` Global bool `json:"global"` Limit int `json:"-"` Remaining int `json:"-"` Reset int64 `json:"-"` Empty bool `json:"-"` }
func ExtractRateLimitInfo ¶
func ExtractRateLimitInfo(resp *http.Response, body []byte) (info *RateLimitInfo, err error)
type RateLimiter ¶
type Requester ¶
type Requester interface { Request(req *Request) (resp *http.Response, body []byte, err error) Get(req *Request) (resp *http.Response, body []byte, err error) Post(req *Request) (resp *http.Response, body []byte, err error) Put(req *Request) (resp *http.Response, body []byte, err error) Patch(req *Request) (resp *http.Response, body []byte, err error) Delete(req *Request) (resp *http.Response, body []byte, err error) }
Click to show internal directories.
Click to hide internal directories.