英文:
Heroku local is not using my latest code. Why?
问题
我正在尝试让一个非常简单的基于数据库的 Golang Heroku 应用程序正常工作,作为一个 Hello World 示例。
我的应用程序在部署到 Heroku 后可以正常工作,如果我在本地手动测试,也可以正常工作,但是 heroku local
始终使用旧版本的代码。具体来说:
$ heroku local
forego | starting web.1 on port 8080
可以正常工作,但是意外地提供了旧版本的应用程序。另一方面,这个命令:
$ go run web.go
以及这个命令:
$ git push heroku master
Everything up-to-date
$ heroku open
都提供了我期望的最新版本的代码。
这真的让我感到困惑。我已经阅读了所有的文档并仔细检查了所有的状态,但没有找到任何迹象表明发生了什么,或者可能导致这种情况的原因。
我最好的猜测是 heroku local
使用的是一个编译的 slug,而这个 slug 并没有得到更新。
英文:
I'm trying to get a very simple database-backed golang heroku app working as a hello world.
The deployed Heroku version of my app is working perfectly, and if I manually test it locally, it works perfectly, but heroku local
is stubbornly using an old version of my code. Specifically:
$ heroku local
forego | starting web.1 on port 8080
works, but unexpectedly serves an older version of the app. On the other hand, this:
$ go run web.go
and this:
$ git push heroku master
Everything up-to-date
$ heroku open
both serve what I expect, which is the latest version of my code.
This is really confusing me. I've read all the documentation and double checked the state of everything, and can't find anything that indicates what is going on, or which could cause it.
My best guess are that heroku local
is using a compiled slug from somewhere that is not getting updated.
答案1
得分: 4
问题在于Golang是一种编译语言,而heroku local
只使用最后一次构建,并不会自动重新构建。解决方法很简单,只需在运行heroku local
之前记得进行编译:
$ go install
如果你在测试时使用go run web.go
,很容易忘记这一点,因为它不需要重新编译,而且Heroku本身会自动构建,所以你可以一直不运行go install
,直到尝试使用heroku local
。
(实际上,我在写完整个问题后就找到了解决方法,但我觉得还是应该发布出来供以后参考。)
英文:
The problem is that golang is a compiled language, and heroku local
just uses the last build and does not initiate the rebuild on its own. The fix is to simply remember to compile before running heroku local
:
$ go install
It is easy to forget this if you use go run web.go
for testing, because that doesn't need a recompile, and heroku itself automatically does the build, so you could get away with never running go install
until you try to use heroku local
.
(I actually figured this out as soon as I had the whole question written out, but I figured I should post anyways for future reference.)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论