-
Notifications
You must be signed in to change notification settings - Fork 126
windows embed paths #1829
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
windows embed paths #1829
Conversation
@@ -46,7 +46,8 @@ func newTemplates(folder, lang string, embedded bool) *templates { | |||
t.addErr = fmt.Errorf("no translation dictionary found for lang %q", lang) | |||
return t | |||
} | |||
if embedded { | |||
if embedded { // slashes even on Windows, see embed pkg docs | |||
t.folder = filepath.ToSlash(t.folder) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be redundant with the changes in buildTemplates
@@ -60,6 +61,9 @@ func newTemplates(folder, lang string, embedded bool) *templates { | |||
|
|||
// filepath constructs the template path from the template ID. | |||
func (t *templates) filepath(name string) string { | |||
if t.embedded { // slashes even on Windows, see embed pkg docs | |||
return t.folder + "/" + name + ".tmpl" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The general advice would be to use path.Join
for embedded paths, instead of filepath.Join
, but this is a very simple operation and path.Join
is overcomplex for the job in this case.
Just tested on Windows 11 and it was alright there too. |
One more review would be good. Ideally, another linux, plus a mac. Wanna double check everything this time so 0.5.1 is workable on all platforms. |
c45dfb1
to
459a19c
Compare
This fixes the embedded file server on Windows. The embed and fs packages user forward slashes as the path separator, even on Windows, so we should not use filepath.Join when accessing files in an embed.FS or fs.FS. Also set Content-Length for embedded file responses.
459a19c
to
6e390c1
Compare
v0.5.0 on Windows is broken when using embedded files because as per the
embed
pkg docs:So doing
filepath.Join
, which is usually "the right thing", fails on Windows. Surprising to say the least. golang/go#45230 golang/go#44305 https://pkg.go.dev/io/fs#ValidPathFor an immediate patch.