limiter

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2022 License: BSD-2-Clause Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type NoopLimiter

type NoopLimiter struct {
}

ServerLimiter provides interface to limit amount of requests

func (NoopLimiter) Capacity

func (l NoopLimiter) Capacity() int

func (NoopLimiter) Enter

func (l NoopLimiter) Enter(ctx context.Context, s string) error

Enter claims one of free slots or blocks until there is one.

func (NoopLimiter) Leave

func (l NoopLimiter) Leave(ctx context.Context, s string)

Frees a slot in limiter

type RealLimiter

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

ServerLimiter provides interface to limit amount of requests

func (RealLimiter) Capacity

func (sl RealLimiter) Capacity() int

func (RealLimiter) Enter

func (sl RealLimiter) Enter(ctx context.Context, s string) error

Enter claims one of free slots or blocks until there is one.

func (RealLimiter) Leave

func (sl RealLimiter) Leave(ctx context.Context, s string)

Frees a slot in limiter

type ServerLimiter

type ServerLimiter interface {
	Capacity() int
	Enter(ctx context.Context, s string) error
	Leave(ctx context.Context, s string)
}

func NewServerLimiter

func NewServerLimiter(servers []string, l int) ServerLimiter

NewServerLimiter creates a limiter for specific servers list.

type SimpleLimiter

type SimpleLimiter chan struct{}

func NewSimpleLimiter

func NewSimpleLimiter(l int) SimpleLimiter

func (SimpleLimiter) Enter

func (l SimpleLimiter) Enter()

func (SimpleLimiter) Leave

func (l SimpleLimiter) Leave()

Jump to

Keyboard shortcuts

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