iofl

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: May 13, 2020 License: MIT Imports: 3 Imported by: 1

README

GoDoc

iofl

The iofl package provides configurable I/O filter chains.

Documentation

Overview

The iofl package provides configurable I/O filter chains.

Index

Constants

This section is empty.

Variables

View Source
var Closed = errors.New("closed")

Closed is returned by a filter that has been closed.

Functions

func Apply

func Apply(r io.ReadCloser, cb func(io.ReadCloser) error) error

Apply calls cb for each io.ReadCloser that implements Filter. The filter's chain is traversed upward until a non-Filter is found. If cb returns and error, that error is returned by Apply.

Types

type Chain

type Chain []LinkDef

Chain defines a list of Filters that are to be applied in order.

type ChainSet

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

ChainSet contains Filters, and Chains composed of those Filters.

func NewChainSet

func NewChainSet(filters ...FilterDef) *ChainSet

NewChainSet returns a ChainSet registered with the given filter definitions. Panics if registration returns an error.

func (*ChainSet) Config added in v0.3.0

func (s *ChainSet) Config() Config

Config returns a copy of the configuration used by the ChainSet.

func (*ChainSet) MustRegister

func (s *ChainSet) MustRegister(filter FilterDef)

MustRegister behaves the same as Register, but panics if an error occurs.

func (*ChainSet) MustSetConfig added in v0.3.0

func (s *ChainSet) MustSetConfig(config Config) *ChainSet

MustSetConfig behaves the same as SetConfig, but panics if an error occurs. Returns the ChainSet.

func (*ChainSet) Register

func (s *ChainSet) Register(filter FilterDef) error

Register registers a filter definition. Returns an error if the filter of the given name already exists.

func (*ChainSet) Resolve

func (s *ChainSet) Resolve(chain string, src io.ReadCloser) (filter Filter, err error)

Resolve locates the chain of the given name, and produces a Filter that recursively applies all filters in the chain. If vars is non-nil, then any Filters that implement Expander will be called with vars. If src is non-nil, then it will be used as the source of the first filter in the chain.

func (*ChainSet) SetConfig added in v0.3.0

func (s *ChainSet) SetConfig(config Config) error

SetConfig uses Config to configure the ChainSet.

type Config

type Config struct {
	// Chains maps a name to a Chain.
	Chains map[string]Chain
}

Config configures a ChainSet.

type Filter

type Filter interface {
	io.ReadCloser
	// Source returns the source from which the Filter is reading, or nil if
	// there is no source.
	Source() io.ReadCloser
}

Filter is implemented by any value that reads from an underlying source while being read. The Close method must close the Source.

type FilterDef

type FilterDef struct {
	Name string
	New  NewFilter
}

FilterDef describes a filter to be added to a ChainSet.

type LinkDef

type LinkDef struct {
	// Filter is the name of the Filter registered with a ChainSet.
	Filter string
	// Params configure the Filter.
	Params Params
}

LinkDef specifies a Filter to be used in a Chain, and describes its configuration.

type NewFilter

type NewFilter func(params Params, r io.ReadCloser) (f Filter, err error)

NewFilter returns a new Filter, configured by the given parameters. An optional io.ReadCloser specifies the source from which data will be read. NewFilter may ignore the io.ReadCloser, or return an error if an io.ReadCloser is required.

type Params

type Params map[string]interface{}

Params contains a set of parameters that configure a Filter.

func (Params) GetInt

func (p Params) GetInt(key string) int

GetInt returns the value of key as an int, or 0 if the key is not present or the value is not a number.

func (Params) GetString

func (p Params) GetString(key string) string

GetString returns the value of key as a string, or an empty string if the key is not present or the value is not a string.

type Root

type Root struct {
	io.ReadCloser
}

Root wraps a general io.ReadCloser to be used as a Filter by returning a nil source.

func (Root) Source

func (Root) Source() io.ReadCloser

Source implements Filter. Returns nil.

Jump to

Keyboard shortcuts

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