shapeio

package
v1.6.1 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2023 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package shapeio provides connections throttling functionality. It is based on https://github.com/fujiwara/shapeio.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Reader

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

Reader implements the io.Reader interface and allows limiting reading speed.

func NewReader

func NewReader(r io.Reader, limiter *rate.Limiter) *Reader

NewReader returns a reader that implements io.Reader with rate limiting.

func (*Reader) Read

func (s *Reader) Read(p []byte) (n int, err error)

Read implements the io.Reader interface for *Reader.

func (*Reader) SetRateLimit

func (s *Reader) SetRateLimit(bytesPerSec float64)

SetRateLimit sets rate limit (bytes/sec) to the reader. It overrides the original limiter that was passed in NewReader.

type Writer

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

Writer implements the io.Reader interface and allows limiting writing speed.

func NewWriter

func NewWriter(w io.Writer, limiter *rate.Limiter) *Writer

NewWriter returns a writer that implements io.Writer with rate limiting.

func (*Writer) SetRateLimit

func (s *Writer) SetRateLimit(bytesPerSec float64)

SetRateLimit sets rate limit (bytes/sec) to the writer. It overrides the original limiter that was passed in NewWriter.

func (*Writer) Write

func (s *Writer) Write(p []byte) (n int, err error)

Write implements the io.Writer interface for *Writer.

Jump to

Keyboard shortcuts

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