-
Notifications
You must be signed in to change notification settings - Fork 0
/
option.go
58 lines (49 loc) · 1.14 KB
/
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package rotate
import (
"os"
)
type option struct {
permission os.FileMode
keeps int
policy PolicyFunc
}
// OptionFunc let you change follow.Reader behavior.
type OptionFunc func(o *option)
// Default values
const (
DefaultPermission = 0600
DefaultKeeps = 5
DefaultSize = 1024 * 1024 * 10
)
func (o *option) apply(opts ...OptionFunc) {
o.permission = DefaultPermission
o.keeps = DefaultKeeps
o.policy = SizeBasedPolicy(DefaultSize)
for _, fn := range opts {
fn(o)
}
}
// WithPermission let you change the file permission
func WithPermission(v os.FileMode) OptionFunc {
return func(o *option) {
o.permission = v
}
}
// WithKeeps let you change keep count of the rotated files
func WithKeeps(v int) OptionFunc {
return func(o *option) {
o.keeps = v
}
}
// WithSizeBasedPolicy let you change the rotate policy
func WithSizeBasedPolicy(size int64) OptionFunc {
return func(o *option) {
o.policy = SizeBasedPolicy(size)
}
}
// WithTimeBasedPolicy let you change the rotate policy
func WithTimeBasedPolicy(fn func(openedAtUnix int64) bool) OptionFunc {
return func(o *option) {
o.policy = TimeBasedPolicy(fn)
}
}