dongxing6802 2013-07-09 18:31
浏览 26

在Go项目中组织资产文件

I have a project that contains a folder to manage file templates, but it doesn't look like Go provides any support for non-Go-code project files. The project itself compiles to an executable, but it needs to know where this template folder is in order to operate correctly. Right now I do a search for $GOPATH/src/<templates>/templates, but this feels like kind of a hack to me because it would break if I decided to rename the package or host it somewhere else.

I've done some searching and it looks like a number of people are interested in being able to "compile" the asset files by embedding them in the final binary, but I'm not sure how I feel about this approach.

Any ideas?

  • 写回答

2条回答 默认 最新

  • drbmhd9583 2013-07-09 20:03
    关注

    Either pick a path (or a list of paths) that users are expected to put the supporting data in (/usr/local/share/myapp, ...) or just compile it into the binary.

    It depends on how you are planning to distribute the program. As a package? With an installer?

    Most of my programs I enjoy just having a single file to deploy and I just have a few templates to include, so I do that.

    I have an example using go-bindata where I build the html template with a Makefile, but if I build with the 'devel' flag it will read the file at runtime instead to make development easier.

    评论

报告相同问题?