prefixpipe

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2019 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Opts

type Opts struct {
	// LogFunc, if set, receives error logs. Defaults to log.Printf from stdlib.
	LogFunc func(string, ...interface{})
}

Opts configures your PrefixPipe.

func DefaultOpts

func DefaultOpts() Opts

DefaultOpts returns the default Opts.

type PrefixPipe

type PrefixPipe struct {
	Opts
	// Dest is the destination writer.
	Dest io.Writer
	// WriterCloser is the receiving Writer which is prefixed and written to
	// Dest. Remember to call Close() when you're done, or you will leak a
	// goroutine.
	io.WriteCloser
	// contains filtered or unexported fields
}

PrefixPipe prefixes all lines written to it, and writes them to Dest.

func New

func New(dest io.Writer, prefix string, config ...func(*Opts)) *PrefixPipe

New returns a new PrefixPipe that prefixes every line written with the formatted string provided and writes it to dest.

Optionally pass one or more config funcs to tweak the options for this PrefixPipe, options start as DefaultOpts() and each config func is run in the order specified from left to right.

To ensure you don't leak goroutines, you must call Close() on the returned *PrefixPipe. To ensure every line gets written to Dest, you must call Wait() after Close().

func (*PrefixPipe) Wait

func (pp *PrefixPipe) Wait() error

Wait waits for the pipe to be closed and to flush all its contents.

Jump to

Keyboard shortcuts

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