/
browser.go
58 lines (52 loc) · 1.02 KB
/
browser.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
package browser
import (
"fmt"
"github.com/ismailbayram/bigpicture/internal/graph"
"regexp"
"strings"
)
const (
LangGo = "go"
LangPy = "py"
LangJava = "java"
)
type Browser interface {
Browse(parentPath string)
}
func NewBrowser(lang string, tree *graph.Tree, ignoredPaths []string, rootDir string) Browser {
switch lang {
case LangGo:
return &GoBrowser{
ignoredPaths: ignoredPaths,
tree: tree,
}
case LangPy:
return &PythonBrowser{
ignoredPaths: ignoredPaths,
tree: tree,
rootDir: rootDir,
}
case LangJava:
return &JavaBrowser{
ignoredPaths: ignoredPaths,
tree: tree,
rootDir: rootDir,
}
}
return nil
}
func isIgnored(ignoredPaths []string, entryPath string) bool {
isIgnored := false
for _, ignore := range ignoredPaths {
regxp := ignore
if strings.HasPrefix(ignore, "*") {
regxp = fmt.Sprintf("^%s$", ignore)
}
re := regexp.MustCompile(regxp)
if re.MatchString(entryPath) {
isIgnored = true
break
}
}
return isIgnored
}