filter

package
v0.0.0-...-22b5626 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2017 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package filter provides general-purpose core.Pipe implementations to filter (i.e. discard), sort or aggregate pipeline items.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewDuplicate

func NewDuplicate(dedupField string) core.Pipe

NewDuplicate instantiates a new filter which removes duplicates in the pipeline. Duplicates are identified by the given dedupField. Only one entry with the same value for the given field is allowed. In case of duplicates, the first entry received from the input channel has priority.

func NewSort

func NewSort(field string, order SortOrder) core.Pipe

NewSort instantiates a new filter, which gathers all entries of the input channel until the input channel is closed. Then, it sorts all entries according to the given field and order and writes the entries to the output channel.

func NewValidator

func NewValidator(validators ...Validator) core.Pipe

NewValidator constructs a new Pipe, which uses the given validators to decide if incoming entries should be dropped.

Types

type SortOrder

type SortOrder int

SortOrder describes either ascending or descending order of items

const (
	// OrderAscending describes an ascending sort order
	OrderAscending SortOrder = iota
	// OrderDescending describes a descending sort order
	OrderDescending
)

type ValidatingFilter

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

ValidatingFilter implements the core.Pipe interface, hence it is a stage in a pipeline. ValidatingFilter defines how Validation is orchestrated. This is a naive implementation: Entries are retrieved from the input channel. For each Entry retrieved, the given validators are called synchronously until a validation error occurs or all validators are passed. This procedure is performed for each Entry in the input channel, until the channel is closed. The policy in case of invalid Entries is, that these Entries are simply dropped (not passed to the output channel).

func (*ValidatingFilter) Process

func (vf *ValidatingFilter) Process(in <-chan core.Entry) <-chan core.Entry

Process items from in chan, validate, pass to out chan if valid.

type Validator

type Validator interface {
	Validate(entry core.Entry) bool
}

A Validator defines the logic how an Entry is validated. It returns true if the Entry is valid.

Jump to

Keyboard shortcuts

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