-
Notifications
You must be signed in to change notification settings - Fork 0
/
tail.go
63 lines (48 loc) · 871 Bytes
/
tail.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
56
57
58
59
60
61
62
63
package tail
import (
"fmt"
"github.com/vela-ssoc/vela-kit/lua"
"gopkg.in/tomb.v2"
)
type tail struct {
lua.SuperVelaData
cfg *config
queue chan line
limit *limit
tom *tomb.Tomb
rn uint64
wn uint64
}
func newTail(cfg *config) *tail {
return &tail{cfg: cfg}
}
func (t *tail) Name() string {
return t.cfg.name
}
func (t *tail) Type() string {
return typeof
}
func (t *tail) constructor() {
//初始化tom
t.tom = new(tomb.Tomb)
//queue
t.queue = make(chan line)
//初始化限速
t.limit = newLimit(t.cfg.limit)
}
func (t *tail) Start() error {
if err := t.cfg.valid(); err != nil {
return err
}
t.constructor()
for i := 0; i < t.cfg.thread; i++ {
go func(k int) { t.output(k) }(i)
}
return nil
}
func (t *tail) Close() error {
//关闭队列
close(t.queue)
t.tom.Kill(fmt.Errorf("%s exit", t.Name()))
return nil
}