英文:
How to run go generate on Heroku
问题
我正在使用http://github.com/tmthrgd/go-bindata来将静态文件和模板嵌入到Go可执行文件中。它要求运行go generate
来运行一个Go代码,该代码读取每个文件并将其二进制表示写入标准的Go文件。在构建过程之前必须触发go generate
。有没有可能配置Heroku来处理这个?
英文:
I am using http://github.com/tmthrgd/go-bindata to embed static files and templates within Go executable file. It requires to run go generate
to run a Go code that read each file and write binary representation as standard go file. go generate
have to be fired before build process.
Is there a chance to configure Heroku to handle this?
答案1
得分: -1
go generate
应该在本地开发时运行,而不是在 Heroku 上运行。如果在 Heroku 上运行它,会导致非常难以调试的问题。如果 go generate
产生了意外的结果,你将无法轻松地检查它。
你可以使用类似 modd 或者 git 钩子这样的工具来运行 go generate
。将 go generate
的结果跟踪到 git 中,也意味着你可以追踪哪些更改影响了生成的代码。
在像 Ruby 这样的语言中,可能习惯在服务器上运行 bundle install
并从 git 中省略依赖项。但对于 Go 程序来说,情况并非如此。依赖项应该被打包并由 git 跟踪。生成的代码也是如此。
对于这种情况,不建议采取以下操作,我也不会这样做。
- fork Go Heroku Buildpack
- 添加一行来运行
go generate
- 使用修改后的 Go Heroku Buildpack
- 部署你的应用程序
英文:
go generate
should be run locally while developing, not on heroku. If you run it on heroku it will lead to very hard to debug issues. If go generate
has unexpected results you wont be able to easily inspect this.
You could run go generate
with a tool like modd or with a git hook.
Having the results of go generate
tracked by git also means that you can track which changes affected generated code.
In a language like ruby it might be customary to run bundle install
on the server and omit dependencies from git. For go programs this is not so. Dependencies should be vendored and tracked by git. Same for generated code.
The rest is not at all advised for this case and I would never do something like this.
- fork the go heroku buildpack
- add a line to run
go generate
- use your modified go heroku buildpack
- deploy your app
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论