-
Notifications
You must be signed in to change notification settings - Fork 0
/
embed.go
45 lines (39 loc) · 878 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
// Package embedpkg provides access to the embedded scripts.
package embedpkg
import (
"embed"
"io/fs"
"path/filepath"
"strings"
)
//go:embed scripts/*
var ScriptsFS embed.FS
func Scripts() embed.FS {
return ScriptsFS
}
type Script struct {
Name string
Filename string
Extension string
Path string
}
func GetScripts() ([]Script, error) {
scriptsFS := Scripts()
entries, err := fs.ReadDir(scriptsFS, "scripts")
if err != nil {
return nil, err
}
var scripts []Script
for _, entry := range entries {
if !entry.IsDir() {
nameWithoutExtension := strings.TrimSuffix(entry.Name(), filepath.Ext(entry.Name()))
scripts = append(scripts, Script{
Name: nameWithoutExtension,
Filename: entry.Name(),
Extension: filepath.Ext(entry.Name()),
Path: filepath.Join("scripts", entry.Name()),
})
}
}
return scripts, nil
}