-
Notifications
You must be signed in to change notification settings - Fork 1
/
fs.go
41 lines (33 loc) · 914 Bytes
/
fs.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 main
import (
"io/ioutil"
"os"
"path/filepath"
)
func readFileAll(path string) ([]byte, error) {
f, err := os.Open(path)
if err != nil {
return nil, err
}
defer f.Close()
buff, err := ioutil.ReadAll(f)
if err != nil {
return nil, err
}
return buff, err
}
func putHistory(baseDir string, history *history, full []byte) error {
return os.WriteFile(filepath.Join(historiesBase(baseDir), history.SqlFilename()), full, os.ModePerm)
}
func putMigrationFile(baseDir string, sqlFileName string, migration []byte) error {
return os.WriteFile(filepath.Join(migrationsBase(baseDir), sqlFileName), migration, os.ModePerm)
}
func historiesBase(baseDir string) string {
return filepath.Join(baseDir, "histories")
}
func migrationsBase(baseDir string) string {
return filepath.Join(baseDir, "migrations")
}
func mainSqlFile(baseDir string) string {
return filepath.Join(baseDir, "main.sql")
}