-
Notifications
You must be signed in to change notification settings - Fork 4.8k
/
Copy pathsweeper_factory.go
48 lines (40 loc) · 1.04 KB
/
sweeper_factory.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
package logger
import (
"errors"
"github.com/goharbor/harbor/src/jobservice/logger/sweeper"
)
// SweeperFactory is responsible for creating a sweeper.Interface based on the settings
type SweeperFactory func(options ...OptionItem) (sweeper.Interface, error)
// FileSweeperFactory creates file sweeper.
func FileSweeperFactory(options ...OptionItem) (sweeper.Interface, error) {
var workDir, duration = "", 1
for _, op := range options {
switch op.Field() {
case "work_dir":
workDir = op.String()
case "duration":
if op.Int() > 0 {
duration = op.Int()
}
default:
}
}
if len(workDir) == 0 {
return nil, errors.New("missing required option 'work_dir'")
}
return sweeper.NewFileSweeper(workDir, duration), nil
}
// DBSweeperFactory creates DB sweeper.
func DBSweeperFactory(options ...OptionItem) (sweeper.Interface, error) {
var duration = 1
for _, op := range options {
switch op.Field() {
case "duration":
if op.Int() > 0 {
duration = op.Int()
}
default:
}
}
return sweeper.NewDBSweeper(duration), nil
}