-
Notifications
You must be signed in to change notification settings - Fork 0
/
file.go
46 lines (33 loc) · 839 Bytes
/
file.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
package lib
import (
"io/ioutil"
"os"
"path/filepath"
)
// FetchFile fetches a file contents
func FetchFile(filePath string) (changesetFileString string, e error) {
// filePath := d.Config.ChangeSetPath + "/changes.sql"
if _, e = os.Stat(filePath); os.IsNotExist(e) {
return
}
var fileBytes []byte
fileBytes, e = ioutil.ReadFile(filePath)
if e != nil {
return
}
changesetFileString = string(fileBytes)
return
}
// ScanDir scans the changeset directory for any file with an extension
func (f *Files) ScanDir(rootPath string, extension string) (paths []string, e error) {
var fileInfos []os.FileInfo
paths = []string{}
fileInfos, e = ioutil.ReadDir(rootPath)
for _, f := range fileInfos {
if f.IsDir() || filepath.Ext(f.Name()) != extension {
continue
}
paths = append(paths, f.Name())
}
return
}