Skip to content
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

Template not found when crosscompile for Windows #6

Open
calindtech opened this issue Jan 21, 2024 · 2 comments
Open

Template not found when crosscompile for Windows #6

calindtech opened this issue Jan 21, 2024 · 2 comments

Comments

@calindtech
Copy link

When running in Linux and running the compiled app in Linux everyting works just fine :)

When i try to compile for windows it works but when i start the application I get file not found.
2024/01/21 01:09:12 html/template: "index.html" is undefined

Here is how i Crosscompile :

`#!/usr/bin/env zsh
myapp="webapp"
echo -n "Enter appname: "
read myapp

for GOOS in darwin linux windows; do
for GOARCH in 386 amd64; do
export GOOS GOARCH
if [ $GOOS = windows ]
then
# if-code
go build -v -o ./dist/$myapp-$GOOS-$GOARCH.exe
elif [ "${GOOS}-${GOARCH}" != "darwin-386" ]
then
go build -v -o ./dist/$myapp-$GOOS-$GOARCH
fi
done
done`

I got a folder named templates and in the main.go i set up the reference to embed like so:

//go:embed all:templates/* templateFS embed.FS

I have tried some variants on just embed, but I don't get it to work.
Is it something known or is it just me?

@mattorchard
Copy link

I am also on Windows, and encountered the same problem while trying to use the Go HTMX Tailwind Example
I logged out the paths being passed to the WalkDirFunc and found they were all being separated by a / despite being on windows (not sure if that's caused by fs or embed or something else entirely).
But in any case, replacing String(os.PathSeparator) with "/" did the trick for me.

@jritsema
Copy link
Owner

jritsema commented Jul 7, 2024

Hi there. So sorry that I missed this issue earlier. I tried to write TemplateParseFSRecursive so that it would be cross-platform. Unfortunately I don't have a Windows machine to test it. I'm open to a pull request if you can verify that it works xplat. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants