-
Notifications
You must be signed in to change notification settings - Fork 5
/
walk.go
52 lines (41 loc) · 893 Bytes
/
walk.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
package repotools
import (
"os"
"path/filepath"
)
// Boots was made for walking the file tree searching for modules.
type Boots struct {
// Directories to skip when iterating.
SkipDirs []string
modulePaths []string
}
// Modules returns a slice of module directory absolute paths.
func (b *Boots) Modules() []string {
return b.modulePaths
}
// Walk is the function to walk folders in the repo searching for go modules.
func (b *Boots) Walk(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if !info.IsDir() {
return nil
}
for _, skip := range b.SkipDirs {
if path == skip {
return filepath.SkipDir
}
}
if !hasGoMod(path) {
return nil
}
b.modulePaths = append(b.modulePaths, path)
return nil
}
func hasGoMod(dir string) bool {
_, err := os.Stat(filepath.Join(dir, "go.mod"))
if err != nil {
return false
}
return true
}