Fix 'go generate ./...' on windows #3708
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When running the
go generate ./...
command,pkg\cheatsheet\generate.go
panics because the embedded translation files cannot be found. Previously mentionned here.This is caused by the method
filepath.Join
, which uses the OS-specific path separator.See filepath.Join documentation.
On Windows, it is
\
(backslash). However,embed.FS.ReadFile
expects the path separator to be/
(slash) regardless of the OS.See embed documentation.
To fulfill the contract of
embed.FS.ReadFile
, thepath.Join
method should be used instead since it always uses slashes as the path separator.See path.Join documentation.
I have tried running
go generate ./...
on Ubuntu using WSL and the functionality seems unchanged.Note
I also ran in another problem coming from
pkg\jsonschema\generate.go
where it panics because the string it is looking for terminates by\n
.However on Windows the new line characters are
\r\n
.The solution was to disable git autocrlf (
git config core.autocrlf false
) and to renomalize the files (git add --renormalize .
) to have the new line character match the one inDocumentationCommentStart
.It might be worth including something in the doc about how to run
go generate ./...
.go generate ./...
)