limit

package
v0.0.0-...-74b529a Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2021 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StatusCodeRate

func StatusCodeRate(counter Counter, getIP IPExtractor, limit, ttl int) mux.MiddlewareFunc

Types

type Counter

type Counter interface {
	GetCount(ctx context.Context, ip string) (int, error)
	Increment(ctx context.Context, ip string, ttl int) error
}

type IPExtractor

type IPExtractor func(*http.Request) string

type MapCounter

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

func NewMapCounter

func NewMapCounter() *MapCounter

func (*MapCounter) GetCount

func (mc *MapCounter) GetCount(ctx context.Context, ip string) (int, error)

func (*MapCounter) Increment

func (mc *MapCounter) Increment(ctx context.Context, ip string, ttl int) error

type RedisCounter

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

func NewRedisCounter

func NewRedisCounter(redisURL string) *RedisCounter

func (*RedisCounter) GetCount

func (rc *RedisCounter) GetCount(ctx context.Context, ip string) (int, error)

func (*RedisCounter) Increment

func (rc *RedisCounter) Increment(ctx context.Context, ip string, ttl int) error

Jump to

Keyboard shortcuts

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