iterator

package
v0.0.0-...-31ca664 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAtEnd = errors.New("end of iterator")
)

Functions

func AsChannel

func AsChannel(iter Iterator, bufferSize ...int) <-chan entries.LogEntry

AsChannel will create a channel that is populated from the Iterator by a new goroutine. If bufferSize is populated, then the returned channel will be a buffered channel.

func Drain

func Drain(iter Iterator)

Drain will drain all entries from a Iterator in a new goroutine. This can be useful as an error fallback in case of an iteration error to prevent upstream blocking.

func Dupe

func Dupe(iter Iterator) (Iterator, Iterator)

Dupe will take control of and branch the duplicate Iterator into two identical iterators. Any LogEntry posted to the source Iterator will be sent to both of the new iterators. This is useful in a case similar to when you want to print messages as well as write them to a file. It's not advised to read from an Iterator that has been passed to Dupe, use one of the returned iterators instead.

func End

func End() (entries.LogEntry, int, error)

End signifies that the end of the stream has been reached.

func Err

func Err(err error) (entries.LogEntry, int, error)

Err makes it easier to return the standard response for Iterator.Next errors.

func Fanout

func Fanout(iter Iterator) (Iterator, Iterator)

Fanout will take control of the input Iterator and output entries received from the input Iterator to one of the output Iterators. It's not advised to read from the input Iterator after passing it to Fanout. If an error occurs during iteration, then Drain will be called on the input.

func IsEnd

func IsEnd(err error) bool

IsEnd returns whether the error indicates the end of a stream.

Types

type Func

type Func func() (entries.LogEntry, int, error)

Func provides a quicker way to implement an Iterator. A Func implements Iterator.Next, and implicitly provides a base Iterate implementation.

func (Func) Iterate

func (f Func) Iterate(iter func(entry entries.LogEntry, i int) error) error

func (Func) Next

func (f Func) Next() (entries.LogEntry, int, error)

type Iterator

type Iterator interface {
	// Next returns the next LogEntry and its offset in the stream.
	// Should return ErrAtEnd if the end of the stream is reached.
	Next() (entries.LogEntry, int, error)
	// Iterate will progress through all LogEntry items in the stream, calling iter for each one along with the offset.
	// If iter returns ErrAtEnd, then iteration will cease, returning a nil error.
	// If any other error is returned, then iteration will cease, and the error will be returned.
	Iterate(iter func(entry entries.LogEntry, i int) error) error
}

func Cancellable

func Cancellable(ctx context.Context, iter Iterator) Iterator

Cancellable wraps an iterator and makes it cancellable by context. When the context is cancelled and Next is called, all LogEntries will be forwarded to Drain.

func Concat

func Concat(base, next Iterator) Iterator

Concat will return entries from next after base has been exhausted.

func Cutter

func Cutter(iter Iterator, opt ...entries.CutOpt) Iterator

Cutter injects entries.Cut for each entry in the iterator.

func Empty

func Empty() Iterator

Empty returns an empty Iterator that immediately returns from a call to Iterate.

func Filter

func Filter(iter Iterator, filter func(entry entries.LogEntry, i int, err error) bool) Iterator

Filter wraps an Iterator with a function that - when it returns true - will allow the return values of Next through. If the wrapped Iterator returns a non-nil error, then all values will be passed through regardless

func FromChannel

func FromChannel(_entries <-chan entries.LogEntry) Iterator

FromChannel will create a new Iterator from a channel of entries.LogEntry.

func FromSlice

func FromSlice(slice []entries.LogEntry) Iterator

func Joiner

func Joiner(iter Iterator, startPatterns ...string) Iterator

Joiner will traverse an Iterator, returning messages that may be joined based on a set of startPatterns. A start pattern defines what a @message value must look like to be interpreted as the start of a log message. Subsequent messages that do not match this pattern will have their @message field appended to the last start line. If the Iterator starts with a LogEntry with a @message field that doesn't match the startPatterns, it will be added as a start anyway.

func Merge

func Merge(a, b Iterator) Iterator

Merge will take over the passed in iterators and forward all log entries elements to the new Iterator. It's advised not to read from an iterator that has been passed to Merge.

func Reassigner

func Reassigner(iter Iterator, spec entries.ReassignSpec) Iterator

Reassigner runs entries.Reassign on each entry that passes through the Iterator.

func Tag

func Tag(iter Iterator, tag string) Iterator

Tag will set the standard tag field to the value specified in tag. If the standard tag field already exists, then the parameter will be appended with a period separator. A Tag is intended to classify the log information in some way to make it easier to filter for later.

func Transformer

func Transformer(iter Iterator, spec entries.TransformSpec) Iterator

Transformer adds entries.Transform logic to this Iterator.

Jump to

Keyboard shortcuts

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