lines

package
v14.1.0-rc4 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2021 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ItemsPerMessage = 20

ItemsPerMessage establishes the threshold to flush the buffer when using the `Send` function. It's a variable instead of a constant to make it possible to override in tests.

Functions

func CopyAndAppend

func CopyAndAppend(s [][]byte, e []byte) [][]byte

CopyAndAppend adds a newly allocated copy of `e` to the `s` slice. Useful to avoid io buffer shennanigans

func Send

func Send(r io.Reader, sender Sender, opts SenderOpts) error

Send reads output from `r`, splits it at `opts.Delimiter`, then handles the buffered lines using `sender`.

Types

type Sender

type Sender func([][]byte) error

Sender handles a buffer of lines from a Git command

type SenderOpts

type SenderOpts struct {
	// Delimiter is the separator used to split the sender's output into
	// lines. Defaults to an empty byte (0).
	Delimiter byte
	// Limit is the upper limit of how many lines will be sent. The zero
	// value will cause no lines to be sent.
	Limit int
	// IsPageToken allows control over which results are sent as part of the
	// response. When IsPageToken evaluates to true for the first time,
	// results will start to be sent as part of the response. This function
	// will	be called with an empty slice previous to sending the first line
	// in order to allow sending everything right from the beginning.
	IsPageToken func([]byte) bool
	// Filter limits sent results to those that pass the filter. The zero
	// value (nil) disables filtering.
	Filter *regexp.Regexp
}

SenderOpts contains fields that Send() uses to determine what is considered a line, and how to handle pagination. That is, how many lines to skip, before a line gets fed into the Sender.

Jump to

Keyboard shortcuts

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