ratelimiter

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var RoleLimits = map[string]struct {
	Limit  int
	Window time.Duration
}{
	"admin":      {Limit: 5000, Window: time.Minute},
	"fis":        {Limit: 1000, Window: time.Minute},
	"utv":        {Limit: 3000, Window: time.Minute},
	"kamk":       {Limit: 1000, Window: time.Minute},
	"klab":       {Limit: 1000, Window: time.Minute},
	"tietoevry":  {Limit: 5000, Window: time.Minute},
	"coachtech":  {Limit: 1000, Window: time.Minute},
	"archinisis": {Limit: 1000, Window: time.Minute},
	"default":    {Limit: 500, Window: time.Minute},
}

Functions

func GetLimitForRole

func GetLimitForRole(role string) (int, time.Duration)

Types

type Config

type Config struct {
	RequestsPerTimeFrame int
	TimeFrame            time.Duration
	Enabled              bool
}

type FixedWindowRateLimiter

type FixedWindowRateLimiter struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewFixedWindowLimiter

func NewFixedWindowLimiter(limit int, window time.Duration) *FixedWindowRateLimiter

func (*FixedWindowRateLimiter) Allow

func (rl *FixedWindowRateLimiter) Allow(ip string) (bool, time.Duration)

type Limiter

type Limiter interface {
	Allow(ip string) (bool, time.Duration)
}

type RedisSlidingLimiter

type RedisSlidingLimiter struct {
	Client *redis.Client
}

func NewRedisSlidingLimiter

func NewRedisSlidingLimiter(client *redis.Client) *RedisSlidingLimiter

func (*RedisSlidingLimiter) Allow

func (r *RedisSlidingLimiter) Allow(ctx context.Context, key string, limit int, window time.Duration) (bool, time.Duration, error)

Jump to

Keyboard shortcuts

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