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

报告相同问题?

悬赏问题

  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应