-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreceiver_stdin.go
55 lines (47 loc) · 882 Bytes
/
receiver_stdin.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
package main
import (
"bufio"
"os"
)
// stdinReceiver implements a receiver that reads data from stdin.
type stdinReceiver struct {
i chan serializer
done chan empty
}
func newStdinReceiver() receiver {
return &stdinReceiver{
i: make(chan serializer),
done: make(chan empty),
}
}
func (s *stdinReceiver) setConfig(c *config) {}
func (s *stdinReceiver) inbox() chan serializer {
return s.i
}
func (s *stdinReceiver) start() {
stdin := make(chan string)
go func(c chan string) {
reader := bufio.NewReader(os.Stdin)
for {
str, err := reader.ReadString('\n')
if err != nil {
return
}
stdin <- str
}
}(stdin)
go func() {
for {
select {
case <-s.done:
return
case str := <-stdin:
s.i <- ourString(str)
l.Printf("Sent received data to aggregator.")
}
}
}()
}
func (s *stdinReceiver) stop() {
close(s.done)
}