-
Notifications
You must be signed in to change notification settings - Fork 0
/
input.go
43 lines (37 loc) · 832 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
package httpsource
import (
"log/slog"
"github.com/sandrolain/event-runner/src/config"
"github.com/sandrolain/event-runner/src/internal/itf"
"github.com/valyala/fasthttp"
)
type HTTPEventInput struct {
connection *HTTPEventConnection
slog *slog.Logger
config config.Input
c chan itf.EventMessage
requests chan *fasthttp.RequestCtx
}
func (s *HTTPEventInput) ingest(ctx *fasthttp.RequestCtx) {
s.requests <- ctx
}
func (s *HTTPEventInput) Receive() (res <-chan itf.EventMessage, err error) {
c := make(chan itf.EventMessage, s.config.Buffer)
s.c = c
go func() {
for r := range s.requests {
c <- &HttpEventMessage{
httpCtx: r,
}
}
}()
res = c
return
}
func (s *HTTPEventInput) Close() (err error) {
if s.c != nil {
close(s.c)
}
err = s.connection.removeInput(s)
return
}