Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 ¶
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.