tokenbucket

package module
v0.0.0-...-c2bc945 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2015 License: MIT Imports: 2 Imported by: 1

README

tokenbucket

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bucket

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

Bucket represents single token bucket

func New

func New(capacity int, rate float32) *Bucket

New is constructor for creating single token bucket with specific capacity (token count) and rate (tokens/second) at which buckets gain free space

func (*Bucket) Add

func (b *Bucket) Add(t time.Time) (int, bool)

Add adds token into bucket, returns free space left in bucket and ok if token was added

func (*Bucket) Capacity

func (b *Bucket) Capacity() int

Capacity returns maximum bucket capacity

func (*Bucket) Check

func (b *Bucket) Check(t time.Time) bool

Check adds token in bucket and returns true if token added

type Buckets

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

Buckets is structure for handling multiple token buckets with same rate and initial capacity

func NewBuckets

func NewBuckets(capacity int, rate float32) *Buckets

NewBuckets is constructor for buckets handler, with initial bucket capacity and rate (tokens/second) at which buckets gain free space

func (*Buckets) Add

func (buckets *Buckets) Add(name string, t time.Time) (space int, ok bool)

Add adds token in bucket with specified name and returns free space left in bucket and ok if token was added

func (*Buckets) Capacity

func (buckets *Buckets) Capacity() int

Capacity returns maximum bucket capacity

func (*Buckets) Check

func (buckets *Buckets) Check(name string, t time.Time) bool

Check adds token in specidfied bucket and returns true if token added

Jump to

Keyboard shortcuts

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