How to install web app with all the internal folders, which is built on golang

124 Views Asked by At

How to use 'go install' or any other command to install/deploy a web-app with the internal folders. I had built a small web-app with the following folder structure.

SampleWebApp
   |--- swa.go
   |--- static/
          |--- css/x.css
          |--- js/y.js
          |--- html/z.html

I am using eclipse ide and when i run as go app, it works well(http://localhost:8080) but when i use command-line to install using

 go install <path>

and try(http://localhost:8080) getting 404 error. Definitely the 'go install' command is not copying the internal folders into the executable file.

1

There are 1 best solutions below

0
On

I think you are a little confused about how the go ecosystem works. Let my try to explain a bit about what's going on. When you say "run as go app" you probably mean that you have a button in eclipse that compiles and executes the program you wrote and thus starts the server on your localhost.

So behind the scenes eclipse is running something like this in your working directory:

cd $GOPATH/src/<name of app>
go build
./<name of app>

When you do the same in your terminal it would probably work as well. Just make sure you have your GOPATH configured properly. The command "go install" on the other hand does almost the same a "go build", but then moves the executable to $GOPATH/bin. Notice that it doesn't run the application. So after a go install you'll still have to launch your app like so.

$GOPATH/bin/<name of app>

But when it installs, it only looks at the go files. So if you want your application to have access to your html, js and css files you should launch it from your working directory. There are ways add the html, css, and js files to the executable using a package like go-bind-data:

https://github.com/jteeuwen/go-bindata

That way you can just move your executable around, and all your files will be inside it. In effect you could then copy this executable to the server and it should work as is.

I hope this clears it up a little.