ratelimit: github.com/ahmedash95/ratelimit Index | Files

package ratelimit

import "github.com/ahmedash95/ratelimit"

Index

Package Files

blocker.go cleaner.go pattern_parser.go rate_limit.go spammer.go

Variables

var (
    Mutex sync.Mutex
)

func BlockerCleaner Uses

func BlockerCleaner(l *Blocker)

func RunLimitCleaner Uses

func RunLimitCleaner(l *Limit)

func SpamCleaner Uses

func SpamCleaner(l *Spammer)

type Block Uses

type Block struct {
    ExpiredAt time.Time
}

type Blocker Uses

type Blocker struct {
    Duration time.Duration
    Values   map[string]*Block
}

func CreateBlocker Uses

func CreateBlocker() Blocker

func (Blocker) AddIfNotExists Uses

func (s Blocker) AddIfNotExists(key string)

type Limit Uses

type Limit struct {
    MaxRequests int
    Per         time.Duration
    Block       time.Duration
    Blocker     Blocker
    MaxSpam     int
    Spammer     Spammer
    Rates       map[string]*RateLimit
}

func CreateLimit Uses

func CreateLimit(key string) Limit

func (*Limit) Hit Uses

func (l *Limit) Hit(key string) error

type Options Uses

type Options struct {
    Max       int
    Per       time.Duration
    Block     time.Duration
    MaxToSpam int
}

type RateLimit Uses

type RateLimit struct {
    ExpiredAt time.Time
    Hits      int
}

func (*RateLimit) Hit Uses

func (r *RateLimit) Hit()

type Spam Uses

type Spam struct {
    ExpiredAt time.Time
    Hits      int
}

type Spammer Uses

type Spammer struct {
    Duration time.Duration
    Values   map[string]*Spam
}

func CreateSpammer Uses

func CreateSpammer() Spammer

func (Spammer) Increase Uses

func (s Spammer) Increase(key string)

Package ratelimit imports 5 packages (graph). Updated 2018-06-03. Refresh now. Tools for package owners.