Files
k3s/pkg/util/bindata/embed.go
muicoder 6f16773c1a refactor: replace go-bindata with native embed package
Signed-off-by: muicoder <muicoder@gmail.com>
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
2025-08-06 16:07:43 -03:00

36 lines
987 B
Go

package bindata
import (
"embed"
"io/fs"
"path/filepath"
"sort"
"strings"
)
// Bindata is a wrapper around embed.FS that allows us to continue to use
// go-bindata style Asset and AssetNames functions to access the embedded FS.
type Bindata struct {
FS *embed.FS
Prefix string
}
func (b Bindata) Asset(name string) ([]byte, error) {
return b.FS.ReadFile(filepath.Join(b.Prefix, name))
}
func (b Bindata) AssetNames() []string {
var assets []string
fs.WalkDir(b.FS, ".", func(path string, entry fs.DirEntry, err error) error {
// do not list hidden files - there is a .empty file checked in as a
// placeholder for files that are generated at build time to satisy
// `go vet`, but these should not be include when listing assets.
if n := entry.Name(); entry.Type().IsRegular() && !strings.HasPrefix(n, ".") && !strings.HasPrefix(n, "_") {
assets = append(assets, strings.TrimPrefix(path, b.Prefix))
}
return nil
})
sort.Strings(assets)
return assets
}