ratelimit

package
v0.0.0-...-24c6111 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2022 License: MIT Imports: 6 Imported by: 0

README

Rate limiter

Inspired by dev.by article

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Request

type Request struct {
	Key      string
	Limit    uint64
	Duration time.Duration
}

type Result

type Result struct {
	State         State
	TotalRequests uint64
	ExpiresAt     time.Time
}

type State

type State int64
const (
	Deny  State = 0
	Allow       = 1
)

type Strategy

type Strategy interface {
	Run(ctx context.Context, r *Request) (*Result, error)
}

func NewRedisStrategy

func NewRedisStrategy(client *redis.Client, now func() time.Time) Strategy

Jump to

Keyboard shortcuts

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