2015-11-03 20:13


I'm making a server in Go for a web app. The app consists of Go code which will act as an http server and a websocket server for the app. It will also include static assets to be served by the Go code, such as html/css/javascript/images/etc. I plan to use go-bindata or equivalent to package the final static assets. The desired form of deployment is a single binary executable with all static assets bundled in.

However, the javascript assets are to be built and organized in such a way that they will require a compilation step before they can be packaged into Go source for inclusion into the compiled binary. This will be accomplished with npm scripts/webpack/gulp/equivalent.

I have read the official Go documentation about the recommended project structure, but it doesn't seem to address my kind of use case.

I don't know if the frontend code and backend code should live in the same git repo or separate ones. I don't know what build process should handle running the javascript compilation process, the go-bindata process, and the go build process. Is there a recommended way to manage this type of project or perhaps some examples of similar successful projects?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答


  • duanchi8112 duanchi8112 6年前

    Here's what I do:

    -main.go //handlers and code
    -static.go //generated

    I use github.com/mjibson/esc to convert everything in static to a virtual filesystem in static.go. If there are additional tasks to generate css/js (I run typescript compiler), those can be run before you embed the assets.

    All of this gets wired up to go generate with comments:

    //go:generate sass or tsc or grunt or whatever
    //go:generate esc -o static.go static
    点赞 评论 复制链接分享