-
Notifications
You must be signed in to change notification settings - Fork 42
/
match.go
73 lines (61 loc) · 981 Bytes
/
match.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
64
65
66
67
68
69
70
71
72
73
package upx
import (
"path/filepath"
"time"
"github.com/upyun/go-sdk/v3/upyun"
)
const (
TIME_NOT_SET = iota
TIME_BEFORE
TIME_AFTER
TIME_INTERVAL
)
const (
ITEM_NOT_SET = iota
DIR
FILE
)
type MatchConfig struct {
Wildcard string
TimeType int
Before time.Time
After time.Time
Start string
End string
ItemType int
}
func IsMatched(upInfo *upyun.FileInfo, mc *MatchConfig) bool {
if mc.Wildcard != "" {
if same, _ := filepath.Match(mc.Wildcard, upInfo.Name); !same {
return false
}
}
switch mc.TimeType {
case TIME_BEFORE:
if !upInfo.Time.Before(mc.Before) {
return false
}
case TIME_AFTER:
if !upInfo.Time.After(mc.After) {
return false
}
case TIME_INTERVAL:
if !upInfo.Time.Before(mc.Before) {
return false
}
if !upInfo.Time.After(mc.After) {
return false
}
}
switch mc.ItemType {
case DIR:
if !upInfo.IsDir {
return false
}
case FILE:
if upInfo.IsDir {
return false
}
}
return true
}