-
Notifications
You must be signed in to change notification settings - Fork 34
/
batch.go
34 lines (29 loc) · 877 Bytes
/
batch.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
package shuttle
import "github.com/heroku/log-shuttle/Godeps/_workspace/src/github.com/nu7hatch/gouuid"
// Batch holds incoming log lines and provides some helpers for dealing with
// the grouping of logLines
type Batch struct {
logLines []LogLine
UUID *uuid.UUID
}
// NewBatch returns a new batch with a capacity pre-set
func NewBatch(capacity int) Batch {
uuid, err := uuid.NewV4()
if err != nil {
panic(err) // probably the only sesnsible thing to do
}
return Batch{
logLines: make([]LogLine, 0, capacity),
UUID: uuid,
}
}
// Add a logline to the batch and return a boolean indicating if the batch is
// full or not
func (b *Batch) Add(ll LogLine) bool {
b.logLines = append(b.logLines, ll)
return len(b.logLines) == cap(b.logLines)
}
// MsgCount returns the number of msgs in the batch
func (b *Batch) MsgCount() int {
return len(b.logLines)
}