-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.go
47 lines (37 loc) · 953 Bytes
/
search.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
package main
import (
"fmt"
"os"
"path/filepath"
"strings"
)
type DatabaseInfo struct {
Name string `json:"name"`
Path string `json:"path"`
}
var skipDirs = map[string]bool{
".git": true,
"node_modules": true,
// Add more directories to skip if needed
}
func searchSQLiteDatabases(rootDir string) []DatabaseInfo {
var dbs []DatabaseInfo
err := filepath.Walk(rootDir, func(path string, info os.FileInfo, err error) error {
if err != nil {
fmt.Printf("Error accessing path %s: %v\n", path, err)
return nil
}
if info.IsDir() && skipDirs[info.Name()] {
return filepath.SkipDir
}
if !info.IsDir() && (strings.HasSuffix(path, ".db") || strings.HasSuffix(path, ".sqlite") || strings.HasSuffix(path, ".sqlite3")) {
db := DatabaseInfo{Name: info.Name(), Path: path}
dbs = append(dbs, db)
}
return nil
})
if err != nil {
fmt.Printf("Error walking through the file system: %v\n", err)
}
return dbs
}