-
Notifications
You must be signed in to change notification settings - Fork 63
/
plugin_runner.go
98 lines (78 loc) · 1.76 KB
/
plugin_runner.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package main
import (
"log"
)
type InputRunner interface {
InChan() chan *PipelinePack
RouterChan() chan *PipelinePack
Start(cf map[string]string)
}
type iRunner struct {
inChan chan *PipelinePack
routerChan chan *PipelinePack
}
func NewInputRunner(in, router chan *PipelinePack) InputRunner {
return &iRunner{
inChan: in,
routerChan: router,
}
}
func (this *iRunner) InChan() chan *PipelinePack {
return this.inChan
}
func (this *iRunner) RouterChan() chan *PipelinePack {
return this.routerChan
}
func (this *iRunner) Start(cf map[string]string) {
intput_type, ok := cf["type"]
if !ok {
log.Fatalln("no type configured")
}
input, ok := input_plugins[intput_type]
if !ok {
log.Fatalln("unkown type ", intput_type)
}
in := input()
err := in.(Input).Init(cf)
if err != nil {
log.Fatalln("in.(Input).Init", err)
}
err = in.(Input).Run(this)
if err != nil {
log.Fatalln("in.(Input).Run", err)
}
}
type OutputRunner interface {
InChan() chan *PipelinePack
Start(cf map[string]string)
}
type oRunner struct {
inChan chan *PipelinePack
}
func NewOutputRunner(in chan *PipelinePack) OutputRunner {
return &oRunner{
inChan: in,
}
}
func (this *oRunner) InChan() chan *PipelinePack {
return this.inChan
}
func (this *oRunner) Start(cf map[string]string) {
output_type, ok := cf["type"]
if !ok {
log.Fatalln("no type configured")
}
output_plugin, ok := output_plugins[output_type]
if !ok {
log.Fatalln("unkown type ", output_type)
}
out := output_plugin()
err := out.(Output).Init(cf)
if err != nil {
log.Fatalln("out.(Output).Init", err)
}
err = out.(Output).Run(this)
if err != nil {
log.Fatalln("out.(Output).Run", err)
}
}