rateplan

package module
Version: v0.0.0-...-ad17343 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2020 License: Apache-2.0 Imports: 9 Imported by: 0

README

Rate plan

The Go package rateplan provides the schedulable rate limit writer.

Documentation

Overview

Package rateplan provides the schedulable rate limit writer.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrParseRatePlan = errors.New("can't convert a string into RatePlan")
)

Functions

This section is empty.

Types

type Clock

type Clock interface {
	// Now returns the current time.
	Now() time.Time
	// Sleep sleeps for at least the given duration.
	Sleep(time.Duration)
}

Clock represents the passage of time in a way that can be faked out for tests.

type Limiter

type Limiter struct {
	io.Writer
	timespan.Span
}

func NewLimiter

func NewLimiter(w io.Writer, bucket *ratelimit.Bucket, span timespan.Span) *Limiter

type RatePlan

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

func NewRatePlan

func NewRatePlan(bytesPerSec int64, span timespan.Span) *RatePlan

func NewRatePlanClock

func NewRatePlanClock(bytesPerSec int64, span timespan.Span, clock Clock) *RatePlan

func ParseRatePlan

func ParseRatePlan(s string) (*RatePlan, error)

func (*RatePlan) NewLimiter

func (rp *RatePlan) NewLimiter(w io.Writer) *Limiter

func (*RatePlan) String

func (rp *RatePlan) String() string

type RatePlans

type RatePlans []*RatePlan

func ParseRatePlans

func ParseRatePlans(s string) (RatePlans, error)

func (RatePlans) NewLimiters

func (rps RatePlans) NewLimiters(w io.Writer) []*Limiter

type Writer

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

func NewWriter

func NewWriter(w io.Writer, plans RatePlans) *Writer

func NewWriterClock

func NewWriterClock(w io.Writer, plans RatePlans, clock Clock) *Writer

func (*Writer) Write

func (w *Writer) Write(b []byte) (int, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL