-
Notifications
You must be signed in to change notification settings - Fork 0
/
input.go
49 lines (42 loc) · 924 Bytes
/
input.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
package pluginsource
import (
"fmt"
"log/slog"
"github.com/sandrolain/event-runner/src/config"
"github.com/sandrolain/event-runner/src/internal/itf"
)
type PluginEventInput struct {
connection *PluginEventConnection
slog *slog.Logger
config config.Input
c chan itf.EventMessage
}
func (s *PluginEventInput) Receive() (res <-chan itf.EventMessage, err error) {
in, e := s.connection.plugin.Input(s.config.Buffer, map[string]string{
"topic": s.config.Topic,
"method": s.config.Method,
"stream": s.config.Stream,
"client": s.config.Client,
})
if e != nil {
err = fmt.Errorf("failed to get input: %w", e)
return
}
c := make(chan itf.EventMessage, s.config.Buffer)
s.c = c
go func() {
for r := range in {
c <- &PluginEventMessage{
input: r,
}
}
}()
res = c
return
}
func (s *PluginEventInput) Close() (err error) {
if s.c != nil {
close(s.c)
}
return
}