1package cowsay
2
3import (
4	"embed"
5	"sort"
6	"strings"
7)
8
9//go:embed cows/*
10var cowsDir embed.FS
11
12// Asset loads and returns the asset for the given name.
13// It returns an error if the asset could not be found or
14// could not be loaded.
15func Asset(path string) ([]byte, error) {
16	return cowsDir.ReadFile(path)
17}
18
19// AssetNames returns the list of filename of the assets.
20func AssetNames() []string {
21	entries, err := cowsDir.ReadDir("cows")
22	if err != nil {
23		panic(err)
24	}
25	names := make([]string, 0, len(entries))
26	for _, entry := range entries {
27		name := strings.TrimSuffix(entry.Name(), ".cow")
28		names = append(names, name)
29	}
30	sort.Strings(names)
31	return names
32}
33
34var cowsInBinary = AssetNames()
35
36// CowsInBinary returns the list of cowfiles which are in binary.
37// the list is memoized.
38func CowsInBinary() []string {
39	return cowsInBinary
40}
41