-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog.go
46 lines (40 loc) · 891 Bytes
/
log.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
package main
import (
"math/rand"
"time"
)
// logKey defines the key used to identify a log.
type logKey struct {
owner int64
token int64
}
// logVal defines the value held in the in-memory cache.
type logVal struct {
endTimestamp int64
rb rollingBuf
label string
notif string
}
// logState captures the in memory state of an actively streaming log.
type logState struct {
logKey
logVal
}
// NewLogState returns a new logState instance.
func newLogState() *logState {
ls := logState{}
ls.owner = ANONYMOUS_OWNER_ID
ls.token = rand.Int63n(MAX_TOKEN_NUM)
ls.endTimestamp = -1
ls.rb = NewRollingBuf(BUFF_ARR_CAP)
return &ls
}
// Implements the PubSub Subscriber interface.
func (ls *logState) SubCb(buf []byte) bool {
if buf == nil {
ls.endTimestamp = time.Now().Unix()
return false
}
ls.rb.AddBuff(buf)
return true // Remain subscribed.
}