writers

package
v0.0.0-...-e5fa29d Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2021 License: Apache-2.0 Imports: 1 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// MaxLinesErr is an instance of MaxLinesError that gets returned by
	// Write() whenever the number of lines written has exceeded the number
	// in |MaxLineWriter.MaxLines|.
	MaxLinesErr = MaxLinesError{"Maximum number of lines written"}
)

Functions

This section is empty.

Types

type MaxLineWriter

type MaxLineWriter struct {
	Dest     io.Writer
	MaxLines uint32
	NumLines uint32
}

MaxLineWriter provides an io.Writer interface that counts the number of lines that have been written. It will stop writing and returns an error if the number of lines written exceeds the number specified in MaxLineWriter.NumLines.

func (*MaxLineWriter) Write

func (w *MaxLineWriter) Write(data []byte) (int, error)

Write() stops writing and returns an error if an attempt is made to write any byte after |MaxLines| newLines have been written. For example, if MaxLines is 1, all bytes will be written up to and including the 1st newline. If there are any bytes in |data| after the 1st newline, an error will be returned.

Callers can change the value of |w.MaxLines| before any call to Write(). Setting MaxLines to 0 will allow any number of newLines.

type MaxLinesError

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

MaxLinesError is the type of error returned by Write() whenever the number of lines written has exceeded the number in |MaxLineWriter.MaxLines|.

func (MaxLinesError) Error

func (e MaxLinesError) Error() string

type PrefixWriter

type PrefixWriter struct {
	Dest        io.Writer
	PrefixFunc  func(w *PrefixWriter) []byte
	NeedsPrefix bool
	NumLines    uint32
}

PrefixWriter makes it easy to prefix lines with a custom prefix. Each time it writes a byte after a newline('\n') character it calls PrefixFunc() to get the byte slice that should be written. |NeedsPrefix| can be set to true to cause a prefix to be written immediately. This is useful for causing a prefix to get written on the first line.

func (*PrefixWriter) Write

func (w *PrefixWriter) Write(data []byte) (int, error)

Jump to

Keyboard shortcuts

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