forked from michenriksen/gitrob
/
matchfile.go
43 lines (38 loc) · 957 Bytes
/
matchfile.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
package matching
import (
"path/filepath"
"strings"
)
type MatchTarget struct {
Path string
Filename string
Extension string
Content string
}
var skippableExtensions = []string{".jpg", ".jpeg", ".png", ".gif", ".bmp", ".tiff", ".tif", ".psd", ".xcf"}
var skippablePathIndicators = []string{"node_modules/", "vendor/bundle", "vendor/cache"}
func (f *MatchTarget) IsSkippable() bool {
ext := strings.ToLower(f.Extension)
path := strings.ToLower(f.Path)
for _, skippableExt := range skippableExtensions {
if ext == skippableExt {
return true
}
}
for _, skippablePathIndicator := range skippablePathIndicators {
if strings.Contains(path, skippablePathIndicator) {
return true
}
}
return false
}
func NewMatchTarget(path string) MatchTarget {
_, filename := filepath.Split(path)
extension := filepath.Ext(path)
return MatchTarget{
Path: path,
Filename: filename,
Extension: extension,
Content: "",
}
}