From 0e61e22b98280fe30821d08cadcf2c21379fce66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Kierski?= Date: Mon, 10 Apr 2023 20:45:28 +0200 Subject: [PATCH] Add additional filepath.ToSlash() `filepath.Join()` also converts slashes to local filesystem separators. It doesn't work properly for embed.FS --- static.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/static.go b/static.go index baf27ac..c8823b2 100644 --- a/static.go +++ b/static.go @@ -45,7 +45,7 @@ func (h *uiAssetsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { } func (h *uiAssetsHandler) indexFilePath() string { - return filepath.Join(h.staticDirPath, h.indexFileName) + return filepath.ToSlash(filepath.Join(h.staticDirPath, h.indexFileName)) } func (h *uiAssetsHandler) renderIndexFile(w http.ResponseWriter) error { @@ -81,7 +81,7 @@ func (h *uiAssetsHandler) serveFile(w http.ResponseWriter, path string) (code in } return http.StatusOK, nil } - path = filepath.Join(h.staticDirPath, path) + path = filepath.ToSlash(filepath.Join(h.staticDirPath, path)) bytes, err := h.contents.ReadFile(path) if err != nil { // If path is error (e.g. file not exist, path is a directory), serve index file.