-
Notifications
You must be signed in to change notification settings - Fork 14
/
reg_files.go
54 lines (44 loc) · 1013 Bytes
/
reg_files.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
50
51
52
53
54
package goql
import (
"sync"
"github.com/fzerorubigd/goql/astdata"
)
type filesProvider struct {
cache map[string][]interface{}
lock *sync.Mutex
}
func (f *filesProvider) Provide(in interface{}) []interface{} {
f.lock.Lock()
defer f.lock.Unlock()
p := in.(*astdata.Package)
if d, ok := f.cache[p.Path()]; ok {
return d
}
fs := p.Files()
res := make([]interface{}, len(fs))
for i := range fs {
res[i] = fs[i]
}
f.cache[p.Path()] = res
return res
}
type nameColumn struct {
}
func (nameColumn) Value(in interface{}) String {
fl := in.(*astdata.File)
return String{String: fl.FileName()}
}
func registerFiles() {
// register files
RegisterTable("files", &filesProvider{
cache: make(map[string][]interface{}),
lock: &sync.Mutex{},
})
RegisterField("files", "name", nameColumn{})
RegisterField("files", "pkg_name", genericPackageName{})
RegisterField("files", "pkg_path", genericPackagePath{})
RegisterField("files", "docs", genericDoc{})
}
func init() {
registerFiles()
}