-
Notifications
You must be signed in to change notification settings - Fork 5
/
embeds.go
67 lines (50 loc) · 1.03 KB
/
embeds.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
58
59
60
61
62
63
64
65
66
67
package foji
import (
"embed"
"fmt"
"strings"
)
//go:embed *
var files embed.FS
const prefix = "foji/"
// Default reads and returns the content of the named file from the embeds.
func Default(name string) ([]byte, error) {
return files.ReadFile(strings.TrimPrefix(name, prefix))
}
func walk(dir string) ([]string, error) {
entries, err := files.ReadDir(dir)
if err != nil {
return nil, fmt.Errorf("readDir:%q:%w", dir, err)
}
currentPath := prefix
if dir != "." {
currentPath += dir + "/"
}
var out []string
for _, f := range entries {
if f.IsDir() {
name := f.Name()
if dir != "." {
name = dir + "/" + name
}
dirFiles, err := walk(name)
if err != nil {
return nil, err
}
out = append(out, dirFiles...)
continue
}
if !strings.HasSuffix(f.Name(), ".tpl") {
continue
}
out = append(out, currentPath+f.Name())
}
return out, nil
}
func AllTemplates() ([]string, error) {
return walk(".")
}
//go:embed foji.yaml
var DefaultConfig string
//go:embed init.yaml
var InitConfig []byte