scroller

package
v4.24.2+incompatible Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2017 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Overview

Package scroller of the Tideland Go Library helps analyzing a continuously written line by line content, e.g. at the monitoring of log files. Here the Scroller is working in the background and allows to read out of any ReadSeeker (which may be a File) from beginning, end or a given number of lines before the end, filter the output by a filter function and write it into a Writer. If a number of lines and a filter are passed the Scroller tries to find that number of lines matching to the filter.

Index

Constants

View Source
const (
	ErrNoSource = iota + 1
	ErrNoTarget
	ErrNegativeLines
)

Error codes of the scroller package.

Variables

This section is empty.

Functions

func IsNegativeLinesError

func IsNegativeLinesError(err error) bool

IsNegativeLinesError returns true, if the error shows the setting of a negative number of lines to start with.

func IsNoSourceError

func IsNoSourceError(err error) bool

IsNoSourceError returns true, if the error signals that no source has been passed.

func IsNoTargetError

func IsNoTargetError(err error) bool

IsNoTargetError returns true, if the error signals that no target has been passed.

Types

type FilterFunc

type FilterFunc func(line []byte) bool

FilterFunc decides if a line shall be scrolled (func is nil or returns true) or not (func returns false).

type Option

type Option func(s *Scroller) error

Option defines a function setting an option.

func BufferSize

func BufferSize(bs int) Option

BufferSize allows to set the initial size of the buffer used for reading.

func Filter

func Filter(ff FilterFunc) Option

Filter sets the filter function of the scroller.

func Lines

func Lines(l int) Option

Lines sets the number of lines ro scroll initially.

func PollTime

func PollTime(pt time.Duration) Option

PollTime defines the frequency the source is polled.

type Scroller

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

Scroller scrolls and filters a ReadSeeker line by line and writes the data into a Writer.

func NewScroller

func NewScroller(source io.ReadSeeker, target io.Writer, options ...Option) (*Scroller, error)

NewScroller starts a Scroller for the given source and target. The options can control the number of lines, a filter, the buffer size and the poll time.

func (*Scroller) Error

func (s *Scroller) Error() (int, error)

Error returns the status and a possible error of the scroller.

func (*Scroller) Stop

func (s *Scroller) Stop() error

Stop tells the scroller to end working.

func (*Scroller) Wait

func (s *Scroller) Wait() error

Wait blocks until the scroller has stopped.

Jump to

Keyboard shortcuts

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