Documentation ¶
Overview ¶
The iofl package provides configurable I/O filter chains.
Index ¶
- Variables
- func Apply(r io.ReadCloser, cb func(io.ReadCloser) error) error
- type Chain
- type ChainSet
- func (s *ChainSet) Config() Config
- func (s *ChainSet) MustRegister(filter FilterDef)
- func (s *ChainSet) MustSetConfig(config Config) *ChainSet
- func (s *ChainSet) Register(filter FilterDef) error
- func (s *ChainSet) Resolve(chain string, src io.ReadCloser) (filter Filter, err error)
- func (s *ChainSet) SetConfig(config Config) error
- type Config
- type Filter
- type FilterDef
- type LinkDef
- type NewFilter
- type Params
- type Root
Constants ¶
This section is empty.
Variables ¶
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 ChainSet ¶
type ChainSet struct {
// contains filtered or unexported fields
}
ChainSet contains Filters, and Chains composed of those Filters.
func NewChainSet ¶
NewChainSet returns a ChainSet registered with the given filter definitions. Panics if registration returns an error.
func (*ChainSet) Config ¶ added in v0.3.0
Config returns a copy of the configuration used by the ChainSet.
func (*ChainSet) MustRegister ¶
MustRegister behaves the same as Register, but panics if an error occurs.
func (*ChainSet) MustSetConfig ¶ added in v0.3.0
MustSetConfig behaves the same as SetConfig, but panics if an error occurs. Returns the ChainSet.
func (*ChainSet) Register ¶
Register registers a filter definition. Returns an error if the filter of the given name already exists.
func (*ChainSet) Resolve ¶
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.
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 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.
type Root ¶
type Root struct {
io.ReadCloser
}
Root wraps a general io.ReadCloser to be used as a Filter by returning a nil source.