rate

package
v3.0.0-...-04a954d Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2021 License: ISC Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const ExtraDelay = 250 * time.Millisecond

ExtraDelay because Discord is trash. I've seen this in both litcord and discordgo, with dgo claiming from experiments. RE: Those who want others to fix it for them: release the source code then.

Variables

View Source
var ErrTimedOutEarly = errors.New(
	"rate: rate limit exceeds context deadline or is blocked acquire options")

ErrTimedOutEarly is the error returned by Limiter.Acquire, if a rate limit exceeds the deadline of the context.Context or api.AcquireOptions.DontWait is set to true

View Source
var MajorRootPaths = []string{"channels", "guilds"}

TODO: webhook

Functions

func EmojiRune

func EmojiRune(r rune) bool

func ParseBucketKey

func ParseBucketKey(path string) string

func StringIsCustomEmoji

func StringIsCustomEmoji(emoji string) bool

func StringIsEmojiOnly

func StringIsEmojiOnly(emoji string) bool

Types

type AcquireOptions

type AcquireOptions struct {
	// DontWait prevents rate.Limiters from waiting for a rate limit. Instead
	// they will return an rate.ErrTimedOutEarly.
	DontWait bool
}

func (AcquireOptions) Context

func (opts AcquireOptions) Context(ctx context.Context) context.Context

Context wraps the given ctx to have the AcquireOptions.

type CustomRateLimit

type CustomRateLimit struct {
	Contains string
	Reset    time.Duration
}

type Limiter

type Limiter struct {
	// Only 1 per bucket
	CustomLimits []*CustomRateLimit

	Prefix string
	// contains filtered or unexported fields
}

func NewLimiter

func NewLimiter(prefix string) *Limiter

func (*Limiter) Acquire

func (l *Limiter) Acquire(ctx context.Context, path string) error

Acquire acquires the rate limiter for the given URL bucket.

func (*Limiter) Release

func (l *Limiter) Release(path string, headers http.Header) error

Release releases the URL from the locks. This doesn't need a context for timing out, since it doesn't block that much.

Jump to

Keyboard shortcuts

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