-
Notifications
You must be signed in to change notification settings - Fork 21
/
prepare_utils.go
49 lines (42 loc) · 1006 Bytes
/
prepare_utils.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
package template
import (
"fmt"
"os"
"path/filepath"
"github.com/vetcher/go-astra"
"github.com/vetcher/go-astra/types"
)
func ParseFile(filename string) (*types.File, error) {
return astra.ParseFile(filename)
}
var parsedCache = map[string]*types.File{}
func parsePackage(path string) (*types.File, error) {
path = filepath.Dir(path)
if file, ok := parsedCache[path]; ok {
return file, nil
}
files, err := astra.ParsePackage(path, astra.AllowAnyImportAliases)
if err != nil {
return nil, err
}
file, err := astra.MergeFiles(files)
if err != nil {
return nil, err
}
parsedCache[path] = file
return file, nil
}
func statFile(absPath, relPath string) error {
outpath, err := filepath.Abs(filepath.Join(absPath, relPath))
if err != nil {
return fmt.Errorf("unable to resolve path: %v", err)
}
fileInfo, err := os.Stat(outpath)
if os.IsNotExist(err) || os.IsPermission(err) {
return err
}
if fileInfo.IsDir() {
return fmt.Errorf("%s is dir", outpath)
}
return nil
}