Deployment of web app html file not found

(Luis Mendes) #1

It’s the first time trying to deploy to a VPS.

In the development machine, source files are in
html are at $GOPATH/src/
static are at $GOPATH/src/

It all works fine, both using go run … as using the binary.

When deploying (to a FreeBSD VPS), what I did was:
copy the binary to $HOME/go/
copy recursively html/ and static/ to $HOME/go/ as well, so ls $HOME/go

But it seems that the app in the VPS can’t find some html file(s).
What am I missing?
Do I have to set GOPATH although I’m not using sources at the VPS?
Place the html/ in another place?
Recreate the directory structure of the development machine under $GOPATH?
What else?

(Johan Dahl) #2

Hi. Which paths do you use inside the go program? And no GOPATH only matters while developing. Your binary don’t know anything about it.

(George Calianu) #3

I suggest you to follow this steps to avoid problems with paths in your application:

  • Build a path to your resources (project folder) available from entire system

      path, err := filepath.Abs(filepath.Dir(os.Args[0]))
      if err != nil {
  • If you use templates also use above path

      if _, err := templ.ParseGlob(filepath.Join(path, "html", "*.html")); err != nil {
  • Most probably you will need a file server for static resources

      http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir(filepath.Join(path, "static")))))
  • Optional, some people (including me) use a deploy tool to copy and run the application in the same conditions on VPS as on your machine. A good one from my toolbox is the cloud tool.

Adjust the above examples as you need. Hope this will help.

(Luis Mendes) #4

At the production box, had a script that was running the app. What I had to do was to include a cd go before exectuting the application.

Thanks both of you.

(Lisa Burns) #5

Very good solution. Thank you.

From BOC Sciences

(system) closed #6

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.