-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathembed.go
57 lines (44 loc) · 853 Bytes
/
embed.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
55
56
57
package builtin
import (
"embed"
"path/filepath"
"strings"
)
//go:embed starlark/*
var StarlarkScripts embed.FS
func Decoders() []data {
return read("decoder")
}
func PostHooks() []data {
return read("posthook")
}
type data struct {
Name string
Script string
}
func read(kind string) []data {
dir, err := StarlarkScripts.ReadDir("starlark")
if err != nil {
panic(err)
}
var items []data
for _, f := range dir {
if f.IsDir() {
continue
}
if !strings.HasPrefix(f.Name(), kind+".") {
continue
}
name := strings.TrimPrefix(f.Name(), kind+".")
name = strings.TrimSuffix(name, ".star")
script, err := StarlarkScripts.ReadFile(filepath.Join("starlark", f.Name()))
if err != nil {
panic(err)
}
items = append(items, data{
Name: "builtin." + name,
Script: string(script),
})
}
return items
}