ratelimit

package
v0.1.33 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewLimiter

NewLimiter configures a RateLimitServer server.

func UnaryInterceptor

func UnaryInterceptor(now func() time.Time, descriptors ...*ratelimitV1.RateLimitDescriptors_Entry) grpc.UnaryClientInterceptor

UnaryServerInterceptor returns a new unary server interceptors that adds zap.Logger to the context.

Types

type MemRateLimiter

type MemRateLimiter struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewFixedMemoryRateLimiter

func NewFixedMemoryRateLimiter(ctx context.Context, now func() time.Time, rate int64, period time.Duration) *MemRateLimiter

NewFixedMemoryRateLimiter returns an in-memory limiter that allows rate/period requests e.g. 100/second, 1000/minute.

func NewSlidingMemoryRateLimiter

func NewSlidingMemoryRateLimiter(ctx context.Context, now func() time.Time, usePercent float64) *MemRateLimiter

NewSlidingMemoryRateLimiter returns an in-memory limiter that attempts to use rate limiting reports to define a window size and set the limits to a fair amount given the `usePercent` argument.

func (*MemRateLimiter) Do

TODO

func (*MemRateLimiter) Report

Report updates the rate limiter with relevant information.

type NoOpRateLimiter

type NoOpRateLimiter struct{}

func (*NoOpRateLimiter) Do

func (*NoOpRateLimiter) Report

Jump to

Keyboard shortcuts

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