-
-
Notifications
You must be signed in to change notification settings - Fork 21
/
embed.go
40 lines (34 loc) · 847 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
package cowsay
import (
"embed"
"sort"
"strings"
)
//go:embed cows/*
var cowsDir embed.FS
// Asset loads and returns the asset for the given name.
// It returns an error if the asset could not be found or
// could not be loaded.
func Asset(path string) ([]byte, error) {
return cowsDir.ReadFile(path)
}
// AssetNames returns the list of filename of the assets.
func AssetNames() []string {
entries, err := cowsDir.ReadDir("cows")
if err != nil {
panic(err)
}
names := make([]string, 0, len(entries))
for _, entry := range entries {
name := strings.TrimSuffix(entry.Name(), ".cow")
names = append(names, name)
}
sort.Strings(names)
return names
}
var cowsInBinary = AssetNames()
// CowsInBinary returns the list of cowfiles which are in binary.
// the list is memoized.
func CowsInBinary() []string {
return cowsInBinary
}