leakybucket

package
v0.0.0-...-44221c2 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2018 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrorFull is returned when the amount requested to add exceeds the remaining space in the bucket.
	ErrorFull = errors.New("add exceeds free capacity")
)

Functions

This section is empty.

Types

type BucketI

type BucketI interface {
	// Capacity of the bucket.
	Capacity() uint
	// Remaining space in the bucket.
	Remaining() uint
	// Reset returns when the bucket will be drained.
	Reset() time.Time
	// Add to the bucket. Returns bucket state after adding.
	Add(uint) (BucketState, error)
}

BucketI interface for interacting with leaky buckets: https://en.wikipedia.org/wiki/Leaky_bucket

type BucketState

type BucketState struct {
	Capacity  uint
	Remaining uint
	Reset     time.Time
}

BucketState is a snapshot of a bucket's properties.

type Storage

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

Storage is a non thread-safe in-memory leaky bucket factory.

func New

func New() *Storage

New initializes the in-memory bucket store.

func (*Storage) Create

func (s *Storage) Create(name string, capacity uint, rate time.Duration) (BucketI, error)

Create a bucket.

type StorageI

type StorageI interface {
	// Create a bucket with a name, capacity, and rate.
	// rate is how long it takes for full capacity to drain.
	Create(name string, capacity uint, rate time.Duration) (BucketI, error)
}

StorageI interface for generating buckets keyed by a string.

Jump to

Keyboard shortcuts

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