Documentation ¶
Overview ¶
Package gopipes implements a concurrent object pipeline mechanism like in MS PowerShell using goroutines and channels.
Index ¶
- func Collect(input, output, err Pipe, params []string)
- func Echo(input, output, err Pipe, params []string)
- func LoadSnapin(name string) (err error)
- func NewStage(name string, impl StageFunc) (err error)
- func PipeToSlice(ch interface{}) interface{}
- func ReadTerminal(input, output, err Pipe, params []string)
- func SortString(input, output, err Pipe, params []string)
- func WriteTerminal(input, output, err Pipe, params []string)
- type Pipe
- type Pipeline
- type Stage
- type StageFunc
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LoadSnapin ¶
LoadSnapin loads a snap-in containing gopipes stages.
func PipeToSlice ¶
func PipeToSlice(ch interface{}) interface{}
PipeToSlice (which was stolen from StackOverflow) reads all data from ch (which must be a chan), returning a slice of the data. If ch is a 'T chan' then the return value is of type []T inside the returned interface. A typical call would be sl := ChanToSlice(ch).([]int) It is exported to make writing stalling stages easier.
func ReadTerminal ¶
ReadTerminal reads from the host's standard input line by line and outputs them as strings.
func SortString ¶
SortString sorts strings from the input pipe. Because it sorts, it must wait for all input to arrive before it can send any output, so it stalls the pipeline.
func WriteTerminal ¶
WriteTerminal writes its input to the host's standard output.
Example ¶
_, out, _, err := Run("Echo hello | WriteTerminal") if err != nil { panic(err) } for range out { }
Output: hello
Types ¶
type Pipe ¶
type Pipe chan interface{}
A Pipe is an arbitrary object pipe.
type Pipeline ¶
type Pipeline []Stage
A Pipeline is a chain of Stages to be connected together with Pipes.
type Stage ¶
type Stage struct {
// contains filtered or unexported fields
}
A Stage is an element that takes in a stream of objects and outputs another such stream.
type StageFunc ¶
StageFunc is a function that can be a pipeline stage.
func ForEach ¶
func ForEach(f func(obj interface{}) interface{}) StageFunc
ForEach creates a wrapper around a function that calls it for each item moving through the pipeline.
Example ¶
f := func(obj interface{}) interface{} { fmt.Println(obj) return nil } line, err := Create("Echo first second third | ForEach") if err != nil { panic(err) } line[1].code = ForEach(f) _, out, _ := Launch(line) for range out { }
Output: first second third