Got error message: panic: html/template: pattern matches no files: `*.html` in Linux server


I developed a web app using Echo and I built the binary on my Windows 10 development machine. Before I built it (which is go build), I have set GOARCH=amd64 and GOOS=linux on Windows Command Prompt.
After getting the binary, I deployed it on my Debian server and used Linux service to start the web app. The web app shows {“message”:“Not Found”} which is not what I expected and the log writes:

panic: html/template: pattern matches no files: *.html
goroutine 1 [running]:
C:/_directory_to_my_development_project/server.go:297 +0x872

Here is snippet from server.go:297:
templates: template.Must(template.ParseGlob("*.html")),

This message is strange for me because it shows that it needs a template library in my development machine even though I already built the binary with Linux settings.


I think ParseGlob reads the templates files at runtime, they are not compiled into the executable. So you need to copy them in the linux machine.


Thanks for reply.
It sounds not right to copy some libraries to another machine.
Is the binary file suppose to have every file and library when we build our web app ?


@auxsoft is right, you are reading the templates from disk. Which consequently means, they must be present on the disk you’re reading them from. When you deploy the binary, you must also deploy the .html files with it.

I’m not exactly sure what do you mean by “not right to copy some libraries”… no one suggested that, unless you refer to .html files as “libraries”, which would be unusual.

Either way, you designed the program. If you designed it to read files from disk, clearly, the files need to be on disk. Nothing unclear about that. However you DO have other choices, you can embed the templates into the binary itself:

Hope this helps!


you must using parse glob