forked from ShiningRush/fastflow
/
file.go
47 lines (38 loc) · 801 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
47
package utils
import (
"io/ioutil"
"os"
"path/filepath"
)
// DagReader
type DagReader interface {
ReadPathsFromDir(dir string) ([]string, error)
ReadDag(path string) ([]byte, error)
}
var (
DefaultReader DagReader = &FileDagReader{}
)
// FileDagReader
type FileDagReader struct {
}
// ReadPathsFromDir
func (r FileDagReader) ReadPathsFromDir(dir string) (dagFiles []string, err error) {
if err = filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
ext := filepath.Ext(path)
if ext != ".yaml" && ext != ".yml" {
return nil
}
dagFiles = append(dagFiles, path)
return nil
}); err != nil {
return
}
return
}
// ReadDag
func (r FileDagReader) ReadDag(path string) ([]byte, error) {
return ioutil.ReadFile(path)
}