limiter

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2018 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package limiter provides a rate limiter

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CallbackParams

type CallbackParams struct {
	// Limiter is the limiter
	Limiter *Limiter
	// GroupID is the id for the concurrency group
	GroupID int
}

CallbackParams represents the callback function parameters

type Limiter

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

Limiter represents a limiter

func New

func New(o Options) (*Limiter, error)

New creates a new limiter by the given options

func (*Limiter) CancelFunc

func (limiter *Limiter) CancelFunc() context.CancelFunc

CancelFunc returns the cancel function

func (*Limiter) Context

func (limiter *Limiter) Context() context.Context

Context returns the context

func (*Limiter) IsCallbackError

func (limiter *Limiter) IsCallbackError() bool

IsCallbackError returns whether the limiter had a rate error

func (*Limiter) IsCanceled

func (limiter *Limiter) IsCanceled() bool

IsCanceled returns whether the limiter is interupted

func (*Limiter) IsDeadline

func (limiter *Limiter) IsDeadline() bool

IsDeadline returns whether the limiter reached deadline

func (*Limiter) IsQueryLimit

func (limiter *Limiter) IsQueryLimit() bool

IsQueryLimit returns whether the limiter reached query limit

func (*Limiter) IsRateError

func (limiter *Limiter) IsRateError() bool

IsRateError returns whether the limiter had a rate error

func (*Limiter) LastError

func (limiter *Limiter) LastError() error

LastError returns the last error

func (*Limiter) NumOfQueries

func (limiter *Limiter) NumOfQueries() int

NumOfQueries returns the number of queries

func (*Limiter) NumOfQueriesByGroupID

func (limiter *Limiter) NumOfQueriesByGroupID(id int) int

NumOfQueriesByGroupID returns the number of queries by the given group id

func (*Limiter) Run

func (limiter *Limiter) Run() error

Run runs the limiter

func (*Limiter) Since

func (limiter *Limiter) Since() time.Duration

Since returns the since value

type Options

type Options struct {
	// Concurrency level
	Concurrency uint32
	// Limit is the limit for the total number of queries
	Limit uint32
	// QPS is the limit for the number of queries per second
	QPS uint32
	// Duration is the limit for making queries
	Duration time.Duration
	// Callback is the function that is invoked on every query
	Callback func(cbp CallbackParams) error
	// SignalHandler enables the signal handler
	SignalHandler bool
}

Options represents the options that can be set when creating a new limiter

Jump to

Keyboard shortcuts

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