-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwriteto_io_processor.go
47 lines (38 loc) · 1 KB
/
writeto_io_processor.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
package pluto
import (
"io"
"go.uber.org/zap"
)
const ProcessorName_WriteToInputOutput = "Write to input/output"
func init() {
PredefinedProcessors[ProcessorName_WriteToInputOutput] = func(args []Value) (p Processor, err error) {
defer creatorPanicHandler(ProcessorName_WriteToInputOutput, &err)()
return WriteToIOProcessor{
Writer: Find("io_interface", args...).Value.(io.Writer),
}, err
}
}
type WriteToIOProcessor struct {
io.Writer
}
func (p WriteToIOProcessor) Process(processable Processable) (Processable, bool) {
b, ok := processable.GetBody().([]byte)
if !ok {
Log.Error("Channels only support []byte to publish")
return processable, false
}
_, err := p.Write(b)
if err != nil {
Log.Debug("Write to io", zap.Error(err))
return processable, false
}
return processable, true
}
func (p WriteToIOProcessor) GetDescriptor() ProcessorDescriptor {
return ProcessorDescriptor{
Name: ProcessorName_WriteToInputOutput,
Description: "",
Input: "",
Output: "",
}
}