access

package
v0.14.2 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2020 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrNoDevice is returned when device is empty or not found in procfs.
	ErrNoDevice = errors.New("no device found")
)

Functions

This section is empty.

Types

type TxController

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

TxController calculates the bytes transmitted every period from the named device.

func NewTxController

func NewTxController(rate uint64) (*TxController, error)

NewTxController creates a new instance initialized to run every second. Caller should run Watch in a goroutine to regularly update the current rate.

func (*TxController) Accept added in v0.14.2

func (tx *TxController) Accept(l net.Listener) (net.Conn, error)

Accept wraps the call to listener's Accept. If the TxController is limited, then Accept immediately closes the connection and returns an error.

func (*TxController) Current added in v0.14.2

func (tx *TxController) Current() uint64

Current exports the current rate. Useful for diagnostics.

func (*TxController) Limit

func (tx *TxController) Limit(next http.Handler) http.Handler

Limit enforces that the TxController rate limit is respected before running the next handler. If the rate is unspecified (zero), all requests are accepted.

func (*TxController) Watch

func (tx *TxController) Watch(ctx context.Context) error

Watch updates the current rate every period. If the context is cancelled, the context error is returned. If the TxController rate is zero, Watch returns immediately. Callers should typically run Watch in a goroutine.

Jump to

Keyboard shortcuts

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