middleware

package
v0.8.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func KeyAuthFunc

func KeyAuthFunc(authenticator preshared.KeyAuthenticator) grpcAuth.AuthFunc

KeyAuthFunc - Middleware that responsible for key authentication

Types

type RateLimiter added in v0.4.4

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

RateLimiter struct is a wrapper around the juju Bucket struct

func NewRateLimiter added in v0.4.4

func NewRateLimiter(reqPerSec int64) *RateLimiter

NewRateLimiter is a constructor function for RateLimiter. It creates a new RateLimiter that allows reqPerSec requests per second.

func (*RateLimiter) Limit added in v0.4.4

func (l *RateLimiter) Limit(_ context.Context) error

Limit checks if a request should be allowed based on the current state of the bucket. If no tokens are available (i.e., if TakeAvailable(1) returns 0), it means the rate limit has been hit, so it returns true. If a token is available, it returns false, meaning the request can proceed.

Jump to

Keyboard shortcuts

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