-
Notifications
You must be signed in to change notification settings - Fork 538
Expand file tree
/
Copy pathreceiver.go
More file actions
67 lines (52 loc) · 1.29 KB
/
receiver.go
File metadata and controls
67 lines (52 loc) · 1.29 KB
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
package loki
// LogReceiverOption is an option argument passed to NewLogsReceiver.
type LogReceiverOption func(*logsReceiver)
func WithChannel(c chan Entry) LogReceiverOption {
return func(l *logsReceiver) {
l.entries = c
}
}
func WithComponentID(id string) LogReceiverOption {
return func(l *logsReceiver) {
l.componentID = id
}
}
// LogsReceiver is an interface providing `chan Entry` which is used for component
// communication.
type LogsReceiver interface {
Chan() chan Entry
}
type logsReceiver struct {
entries chan Entry
componentID string
}
func (l *logsReceiver) Chan() chan Entry {
return l.entries
}
func (l *logsReceiver) String() string {
return l.componentID + ".receiver"
}
func NewLogsReceiver(opts ...LogReceiverOption) LogsReceiver {
l := &logsReceiver{}
for _, o := range opts {
o(l)
}
if l.entries == nil {
l.entries = make(chan Entry)
}
return l
}
// LogsBatchReceiver is an interface providing `chan []Entry`. This should be used when
// multiple entries need to be sent over a channel.
type LogsBatchReceiver interface {
Chan() chan []Entry
}
func NewLogsBatchReceiver() LogsBatchReceiver {
return &logsBatchReceiver{c: make(chan []Entry)}
}
type logsBatchReceiver struct {
c chan []Entry
}
func (l *logsBatchReceiver) Chan() chan []Entry {
return l.c
}