ratelimiter

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: May 16, 2017 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RateLimiter

type RateLimiter interface {
	Limit(logger logger.Logger) bool
	Expired() bool
}

RateLimiter is an interface for implementing a rate limiter

type RsyslogStyle

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

RsyslogStyle is a rate limiter that works similar to rsyslog (and journald's) rate limiters, allowing you to set an interval and a burst. If there are more messages than burst in a given interval, all further messages are dropped until the end of that interval.

func NewRsyslogStyle

func NewRsyslogStyle(interval time.Duration, burst int) *RsyslogStyle

NewRsyslogStyle returns a RateLimiter based on rsyslog's rate limiter

func (*RsyslogStyle) Expired

func (r *RsyslogStyle) Expired() bool

Expired returns whether or not this rate limiter is able to be removed. We mark an RsyslogStyle rate limiter expired if there have been no checks issued for an hour.

func (*RsyslogStyle) Limit

func (r *RsyslogStyle) Limit(logger logger.Logger) bool

Limit should be called each time you want to test if you've reached your rate limit. It will return true if you are over the limit and false otherwise.

Jump to

Keyboard shortcuts

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