ratelimiter

package
v0.0.0-...-85a377b Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var StFormat = "2006-01-02 15:04:05"

Functions

func CheckRateLimit

func CheckRateLimit(ctx context.Context, keyType string, key string, limitConf *LimiterConfig, rateConfig *RateConfig) (*time.Time, error)

func GetBlockTime

func GetBlockTime(block *time.Time) float64

func GetEnvBoolean

func GetEnvBoolean(key string) (bool, bool)

func GetEnvLargeint

func GetEnvLargeint(key string) (int64, bool)

func GetEnvString

func GetEnvString(key string) (string, bool)

func PrintfD

func PrintfD(config *LimiterConfig, format string, keyType string, key string, a ...any) (n int, err error)

func PrintfWD

func PrintfWD(config *LimiterConfig, format string, a ...any) (n int, err error)

Types

type LimiterConfig

type LimiterConfig struct {
	IP             *RateConfig                               `json:"ip"`
	Token          *RateConfig                               `json:"token"`
	CustomTokens   *map[string]*RateConfig                   `json:"tokens"`
	StorageAdapter adapters.RateLimitStorageAdapter          `json:"-"`
	ResponseWriter response_writer.RateLimiterResponseWriter `json:"-"`
	Debug          bool                                      `json:"debug"`
	DisableEnvs    bool                                      `json:"disableEnvs"`
}

func SetConfiguration

func SetConfiguration(config *LimiterConfig) *LimiterConfig

func (*LimiterConfig) GetRateLimiterRateConfigForToken

func (c *LimiterConfig) GetRateLimiterRateConfigForToken(token string) (*RateConfig, bool)

type RateConfig

type RateConfig struct {
	MaxRequestsPerSecond  int64 `json:"maxRequestsPerSecond"`
	BlockTimeMilliseconds int64 `json:"blockTimeMilliseconds"`
}

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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