xio

package
v0.11.36 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2021 License: Apache-2.0 Imports: 3 Imported by: 1

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	// ErrRateLimitExceeded is returned by decorated io.Writer for which the rate
	// limit has been exceeded.
	ErrRateLimitExceeded = errors.New("rate of writing bytes exceeded")
	// ErrSizeLimitExceeded is returned by decorated io.Writer for which the size
	// limit has been exceeded.
	ErrSizeLimitExceeded = errors.New("limit of written bytes exceeded")
)

Functions

func DecorateWriter

func DecorateWriter(writer io.Writer, decorators ...WriterDecorator) io.Writer

DecorateWriter returns writer, based on the passed one, decorated with passed decorators.

Example
package main

import (
	"fmt"
	"os"

	"github.com/allegro/mesos-executor/xio"
)

func main() {
	writer := xio.DecorateWriter(os.Stdout,
		xio.SizeLimit(1),
		xio.RateLimit(1))

	_, err := writer.Write([]byte("bytes"))

	fmt.Println(err)

}
Output:

limit of written bytes exceeded

Types

type WriterDecorator

type WriterDecorator func(io.Writer) io.Writer

WriterDecorator is a type representing functions that can be used to add (to decorate writer with) functionality to the passed writer.

func RateLimit

func RateLimit(limit int) WriterDecorator

RateLimit decorator is used to add a rate limit (number of Write calls per second) for io.Writer. If write rate exceeds the passed limit it will return an error.

func SizeLimit

func SizeLimit(size int) WriterDecorator

SizeLimit decorator is used to add a size limit (number of bytes) for io.Writer. If written bytes length exceeds the passed limit it will return an error.

type WriterFunc

type WriterFunc func([]byte) (int, error)

WriterFunc type is an adapter to allow the use of ordinary functions as io.Writers. If f is a function with the appropriate signature, WriterFunc(f) is a Writer that calls f.

func (WriterFunc) Write

func (w WriterFunc) Write(p []byte) (int, error)

Jump to

Keyboard shortcuts

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