/
records.go
51 lines (41 loc) · 1.13 KB
/
records.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
package inputtest
import (
"github.com/AdRoll/baker"
)
// RecordsDesc describes the Records input. This input is made for testing.
var RecordsDesc = baker.InputDesc{
Name: "Records",
New: NewRecords,
Config: &RecordsConfig{},
}
// RecordsConfig holds the log lines to be fed to the Baker topology.
type RecordsConfig struct {
Records []baker.Record
}
// A Records input is a Baker input used for testing.
type Records struct {
RecordsConfig
}
// NewRecords creates a Records baker input.
func NewRecords(cfg baker.InputParams) (baker.Input, error) {
if cfg.DecodedConfig == nil {
cfg.DecodedConfig = &RecordsConfig{}
}
dcfg := cfg.DecodedConfig.(*RecordsConfig)
return &Records{
RecordsConfig: *dcfg,
}, nil
}
func (in *Records) Run(output chan<- *baker.Data) error {
var buf []byte
// Send all lines via a single baker.Data blob.
for _, ll := range in.Records {
buf = ll.ToText(buf)
buf = append(buf, '\n')
}
output <- &baker.Data{Bytes: buf}
return nil
}
func (Records) Stop() {}
func (Records) FreeMem(data *baker.Data) {}
func (Records) Stats() (stats baker.InputStats) { return }