Embed: Normalize path separator for Windows

* Windows was asking for files like "assets\doodads\" and the embedded
  files used Unix-like paths so no assets could be loaded!
This commit is contained in:
Noah 2021-07-19 22:15:40 -07:00
parent 3949934bc1
commit fbeeb207a8

View File

@ -22,6 +22,9 @@ var Embedded embed.FS
// AssetDir returns the list of embedded files at the directory name.
func AssetDir(name string) ([]string, error) {
// normalize path separators, for Windows
name = strings.ReplaceAll(name, "\\", "/")
var result []string
name = strings.TrimPrefix(name, "assets/")
@ -42,6 +45,9 @@ func AssetDir(name string) ([]string, error) {
// Asset returns the byte data of an embedded asset.
func Asset(name string) ([]byte, error) {
// normalize path separators, for Windows
name = strings.ReplaceAll(name, "\\", "/")
return Embedded.ReadFile(strings.TrimPrefix(name, "assets/"))
}