limiter

package
v0.0.0-...-eece359 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

https://juejin.cn/post/7056068978862456846

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LimitFlowAllow

func LimitFlowAllow()

limit flow golang rate

func LimitFlowReserve

func LimitFlowReserve()

func LimitFlowWait

func LimitFlowWait()

Types

type Clock

type Clock interface {
	Now() time.Time
	Sleep(time.Duration)
}

type FixedWindowLimiter

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

func NewFixWindowLimiter

func NewFixWindowLimiter(limit int, window time.Duration) *FixedWindowLimiter

func (*FixedWindowLimiter) TryAcquire

func (l *FixedWindowLimiter) TryAcquire() bool

type LeakyBucketLimiter

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

func NewLeakyBucketLimit

func NewLeakyBucketLimit(peakLevel, currentVelocy int) *LeakyBucketLimiter

func (*LeakyBucketLimiter) TryAcquire

func (l *LeakyBucketLimiter) TryAcquire() bool

type Limiter

type Limiter interface {
	Take() time.Time
}

type Option

type Option interface {
	// contains filtered or unexported methods
}

type SlidingWindowLimiter

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

func NewSlidingWindowLimiter

func NewSlidingWindowLimiter(limit int, window time.Duration, smallWindow time.Duration) (*SlidingWindowLimiter, error)

func (*SlidingWindowLimiter) TryAcquire

func (l *SlidingWindowLimiter) TryAcquire() bool

type TokenBucketLimiter

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

func NewTokenBucketLimiter

func NewTokenBucketLimiter(capacity, rate int) *TokenBucketLimiter

func (*TokenBucketLimiter) TryAcquire

func (l *TokenBucketLimiter) TryAcquire() bool

Jump to

Keyboard shortcuts

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