drcmg28484 2015-11-03 20:13
浏览 54
已采纳

对于需要编译的静态资产项目,建议使用Go项目结构和构建系统吗?

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?

  • 写回答

1条回答 默认 最新

  • duanchi8112 2015-11-03 23:50
    关注

    Here's what I do:

    $GOPATH/src/github.com/myname/myproject:
    -main.go //handlers and code
    -static.go //generated
    -static
        -js
          -foo.js
        -html
        -css
        -img
    

    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
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败