forked from oelmekki/pgrebase
-
Notifications
You must be signed in to change notification settings - Fork 0
/
source_walker.go
65 lines (54 loc) · 1.33 KB
/
source_walker.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
59
60
61
62
63
64
65
package main
import (
"path/filepath"
"os"
)
type SourceWalker struct {
Config *Config
}
/*
* Load all source files paths
*/
func ( walker *SourceWalker ) Process() {
walker.Config.FunctionFiles = walker.findFunctions()
walker.Config.TriggerFiles = walker.findTriggers()
walker.Config.TypeFiles = walker.findTypes()
walker.Config.ViewFiles = walker.findViews()
return
}
/*
* Find path of function files
*/
func ( walker *SourceWalker ) findFunctions() ( paths []string ) {
return walker.sqlFilesIn( walker.Config.SqlDirPath + "/functions" )
}
/*
* Find path of trigger files
*/
func ( walker *SourceWalker ) findTriggers() ( paths []string ) {
return walker.sqlFilesIn( walker.Config.SqlDirPath + "/triggers" )
}
/*
* Find path of type files
*/
func ( walker *SourceWalker ) findTypes() ( paths []string ) {
return walker.sqlFilesIn( walker.Config.SqlDirPath + "/types" )
}
/*
* Find path of view files
*/
func ( walker *SourceWalker ) findViews() ( paths []string ) {
return walker.sqlFilesIn( walker.Config.SqlDirPath + "/views" )
}
/*
* Walk a directory to find sql files
*/
func ( walker *SourceWalker ) sqlFilesIn( path string ) ( paths []string ) {
filepath.Walk( path, func( path string, info os.FileInfo, err error ) error {
if IsSqlFile( path ) {
paths = append( paths, path )
}
return nil
})
return
}