From fbeeb207a819d74a5c52d51fc83a9f111ef0f6db Mon Sep 17 00:00:00 2001 From: Noah Petherbridge Date: Mon, 19 Jul 2021 22:15:40 -0700 Subject: [PATCH] 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! --- assets/assets_embed.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/assets/assets_embed.go b/assets/assets_embed.go index 5ebb319..ac18c67 100644 --- a/assets/assets_embed.go +++ b/assets/assets_embed.go @@ -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/")) }