-
Notifications
You must be signed in to change notification settings - Fork 2
/
io.go
41 lines (33 loc) · 888 Bytes
/
io.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
package migrations
import (
"io"
"io/ioutil"
"os"
)
// Reader interface allows the migrations to be read from different sources,
// such as an S3 bucket or another data store.
type Reader interface {
// Files returns the files in a directory or remote path.
Files(directory string) ([]string, error)
// Read the SQL from the migration.
Read(path string) (io.Reader, error)
}
// DiskReader outputs to disk, the Migrations default.
type DiskReader struct {
}
// Files reads the filenames from disk.
func (d *DiskReader) Files(directory string) ([]string, error) {
files, err := ioutil.ReadDir(directory)
if err != nil {
return nil, err
}
var paths []string
for _, info := range files {
paths = append(paths, info.Name())
}
return paths, nil
}
// Read the SQL migration from disk.
func (d *DiskReader) Read(path string) (io.Reader, error) {
return os.Open(path)
}