-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathfunchook.go
77 lines (61 loc) · 1.86 KB
/
funchook.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package main
import (
"bytes"
. "github.com/scipipe/scipipe"
)
func main() {
wf := NewWorkflow("FuncHookWf", 4)
foo := NewFooer(wf, "foo")
f2b := NewFoo2Barer(wf, "f2b")
foo.OutFoo().To(f2b.InFoo())
wf.Run()
}
// ------------------------------------------------------------------------
// Components
// ------------------------------------------------------------------------
// Fooer
type Fooer struct {
*Process
name string
}
func NewFooer(wf *Workflow, name string) *Fooer {
// Initiate task from a "shell like" pattern, though here we
// just specify the out-port foo
innerFoo := NewProc(wf, "fooer", "{o:foo}")
// Set the output formatter to a static string
innerFoo.SetOut("foo", "foo.txt")
// Create the custom execute function, with pure Go code
innerFoo.CustomExecute = func(task *Task) {
task.OutIP("foo").Write([]byte("foo\n"))
}
// Connect the ports of the outer task to the inner, generic one
fooer := &Fooer{
innerFoo,
name,
}
return fooer
}
func (p *Fooer) OutFoo() *OutPort { return p.Out("foo") }
// Foo2Barer
type Foo2Barer struct {
*Process
name string
}
func NewFoo2Barer(wf *Workflow, name string) *Foo2Barer {
// Initiate task from a "shell like" pattern, though here we
// just specify the in-port foo and the out-port bar
innerProc := NewProc(wf, "foo2bar", "{i:foo}{o:bar}")
// Set the output formatter to extend the path on the "bar"" in-port
innerProc.SetOut("bar", "{i:foo}.bar.txt")
// Create the custom execute function, with pure Go code
innerProc.CustomExecute = func(task *Task) {
task.OutIP("bar").Write(bytes.Replace(task.InIP("foo").Read(), []byte("foo"), []byte("bar"), 1))
}
// Connect the ports of the outer task to the inner, generic one
return &Foo2Barer{
innerProc,
name,
}
}
func (p *Foo2Barer) InFoo() *InPort { return p.In("foo") }
func (p *Foo2Barer) OutBar() *OutPort { return p.Out("bar") }