forked from powerman/tail
/
option.go
34 lines (26 loc) · 835 Bytes
/
option.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 tail
import "time"
// Defaults for corresponding options.
const (
DefaultPollDelay = 200 * time.Millisecond
DefaultPollTimeout = time.Second
)
// Option let you change Tail behaviour.
type Option interface {
apply(*Tail)
}
type optionFunc func(*Tail)
func (f optionFunc) apply(t *Tail) { f(t) }
// PollDelay let you change delay between polling to save CPU.
func PollDelay(d time.Duration) Option {
return optionFunc(func(t *Tail) { t.pollDelay = d })
}
// PollTimeout let you change how long to wait before return error when
// failed to open or read file.
func PollTimeout(d time.Duration) Option {
return optionFunc(func(t *Tail) { t.pollTimeout = d })
}
// Whence lets you change where you want to start with tailing the file.
func Whence(w int) Option {
return optionFunc(func(t *Tail) { t.whence = w })
}