gopipes

package module
v0.0.0-...-98a634a Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2018 License: GPL-3.0 Imports: 7 Imported by: 0

README

Go package gopipes

pipeline status

Package gopipes implements a concurrent object pipeline mechanism like in MS PowerShell using goroutines and channels.

Documentation

Overview

Package gopipes implements a concurrent object pipeline mechanism like in MS PowerShell using goroutines and channels.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Collect

func Collect(input, output, err Pipe, params []string)

Collect collects input objects into a slice and outputs the slice.

func Echo

func Echo(input, output, err Pipe, params []string)

Echo outputs each of its parameters.

func LoadSnapin

func LoadSnapin(name string) (err error)

LoadSnapin loads a snap-in containing gopipes stages.

func NewStage

func NewStage(name string, impl StageFunc) (err error)

NewStage registers a new type of stage. It is not concurrency-safe.

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

func ReadTerminal(input, output, err Pipe, params []string)

ReadTerminal reads from the host's standard input line by line and outputs them as strings.

func SortString

func SortString(input, output, err Pipe, params []string)

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

func WriteTerminal(input, output, err Pipe, params []string)

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.

func Launch

func Launch(p Pipeline) (in, out, err Pipe)

Launch starts goroutines for all the stages of a pipeline and connects them with pipes.

func Run

func Run(spec string) (in, out, errStrm Pipe, err error)

Run is a wrapper around Create and Launch.

type Pipeline

type Pipeline []Stage

A Pipeline is a chain of Stages to be connected together with Pipes.

func Create

func Create(spec string) (line Pipeline, err error)

Create builds a pipeline out of a string.

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

type StageFunc func(input, output, err Pipe, params []string)

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

Jump to

Keyboard shortcuts

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