-
Notifications
You must be signed in to change notification settings - Fork 56
/
filter.go
46 lines (39 loc) · 1.08 KB
/
filter.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
package serverHandler
import "os"
func (h *handler) FilterItems(items []os.FileInfo) []os.FileInfo {
if h.shows == nil &&
h.showDirs == nil &&
h.showFiles == nil &&
h.hides == nil &&
h.hideDirs == nil &&
h.hideFiles == nil {
return items
}
filtered := make([]os.FileInfo, 0, len(items))
for _, item := range items {
shouldShow := true
if h.shows != nil {
shouldShow = shouldShow && h.shows.MatchString(item.Name())
}
if h.showDirs != nil && item.IsDir() {
shouldShow = shouldShow && h.showDirs.MatchString(item.Name())
}
if h.showFiles != nil && !item.IsDir() {
shouldShow = shouldShow && h.showFiles.MatchString(item.Name())
}
shouldHide := false
if h.hides != nil {
shouldHide = shouldHide || h.hides.MatchString(item.Name())
}
if h.hideDirs != nil && item.IsDir() {
shouldHide = shouldHide || h.hideDirs.MatchString(item.Name())
}
if h.hideFiles != nil && !item.IsDir() {
shouldHide = shouldHide || h.hideFiles.MatchString(item.Name())
}
if shouldShow && !shouldHide {
filtered = append(filtered, item)
}
}
return filtered
}