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


#1

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]:
html/template.Must(…)
C:/Go/src/html/template/template.go:372
main.main()
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.


#2

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.


#3

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 ?


#4

@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: https://echo.labstack.com/cookbook/embed-resources

Hope this helps!
Alex


#5

you must using parse glob