limiter

package
v0.9.7-rc2 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2021 License: Apache-2.0, MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Limiter

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

Limiter is used to restrict access to a resources till a future time

func NewLimiter

func NewLimiter(tm Time) *Limiter

NewLimiter returns a new limiter

func (*Limiter) Add

func (l *Limiter) Add(addr string, t time.Time)

Add limits value till a given time

func (*Limiter) Clean

func (l *Limiter) Clean()

Clean removes all values which a call to Ready would return true

func (*Limiter) Clear

func (l *Limiter) Clear(addr string)

Clear removes value from the limiter. Any calls to Ready for the value will return true after a call to Clear for it.

func (*Limiter) Ready

func (l *Limiter) Ready(addr string) (time.Duration, bool)

Ready checks to see if the time has expired. Returns a time.Duration for the time remaining till a true value will be returned

type Time

type Time interface {
	Until(time.Time) time.Duration
}

Time interface defines required time methods for the Limiter struct. Primarily used for testing

Jump to

Keyboard shortcuts

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