-
Notifications
You must be signed in to change notification settings - Fork 0
/
filefilter.go
48 lines (39 loc) · 826 Bytes
/
filefilter.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 filemonitor
import (
"github.com/nzlov/go/array"
"strings"
)
type FileFilter struct {
filterList *array.Array
}
func NewFileFilter() *FileFilter {
return &FileFilter{array.NewArray()}
}
func (this *FileFilter) AddFilter(filter string) {
this.filterList.Add(filter)
}
func (this *FileFilter) DelFilter(filter string) bool {
return this.filterList.RemoveValue(filter)
}
func (this *FileFilter) SetFilters(filters ...string) {
for _, filter := range filters {
if filter != "" {
this.AddFilter(filter)
}
}
}
func (this FileFilter) Check(path string) bool {
for i := 0; i < this.filterList.Size(); i++ {
v, err := this.filterList.Get(i)
if err != nil {
continue
}
switch inst := v.(type) {
case string:
if strings.HasSuffix(path, inst) {
return true
}
}
}
return false
}