From 07e6fd48313b3f106b280b98b6c25c9d16bc103b Mon Sep 17 00:00:00 2001 From: Yanhu007 Date: Thu, 16 Apr 2026 09:04:43 +0800 Subject: [PATCH] fix: use path instead of filepath in FSLoader for cross-platform fs.FS compatibility On Windows, filepath.Join and filepath.Dir use backslashes as separators. However, fs.FS (including embed.FS) requires forward slashes per the io/fs specification. This causes "unable to resolve template" errors when using FSLoader on Windows. Switch FSLoader.Abs to use the path package (forward slashes) instead of filepath (OS-specific separators). LocalFilesystemLoader continues to use filepath since it accesses the real filesystem. Fixes #373 --- template_loader.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/template_loader.go b/template_loader.go index 8d88005..2ee6872 100644 --- a/template_loader.go +++ b/template_loader.go @@ -7,6 +7,7 @@ import ( "io/fs" "log" "os" + gopath "path" "path/filepath" ) @@ -25,7 +26,9 @@ func NewFSLoader(fs fs.FS) *FSLoader { } func (l *FSLoader) Abs(base, name string) string { - return filepath.Join(filepath.Dir(base), name) + // Use path (not filepath) so that fs.FS paths always use forward + // slashes, even on Windows where filepath uses backslashes. + return gopath.Join(gopath.Dir(base), name) } func (l *FSLoader) Get(path string) (io.Reader, error) {