Heroku Go app崩溃了

sar*_*gas 2 heroku go http-status-code-503

按照本教程,一切都在本地工作.将我的应用程序部署到Heroku并在浏览器上访问应用程序后,我收到503错误并显示以下消息:

应用程序错误应用程序中发生错误,无法提供您的页面.请稍后重试.如果您是应用程序所有者,请检查日志以获取详细信息.

日志说:

2015-09-08T16:31:53.976824+00:00 heroku[web.1]: State changed from crashed to starting
2015-09-08T16:31:56.174376+00:00 heroku[web.1]: Starting process with command `mywebsite`
2015-09-08T16:31:59.312461+00:00 app[web.1]: Listening on port: 39461
2015-09-08T16:32:56.471550+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2015-09-08T16:32:56.471550+00:00 heroku[web.1]: Stopping process with SIGKILL
2015-09-08T16:32:57.390752+00:00 heroku[web.1]: Process exited with status 137
2015-09-08T16:32:57.404208+00:00 heroku[web.1]: State changed from starting to crashed
2015-09-08T16:32:57.645135+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=boiling-eyrie-6897.herokuapp.com request_id=ec26... fwd="xx.xxx.xxx.xxx" dyno= connect= service= status=503 bytes=
2015-09-08T16:32:58.233774+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=boiling-eyrie-6897.herokuapp.com request_id=ef40...fwd="xx.xxx.xxx.xxx" dyno= connect= service= status=503 bytes=
Run Code Online (Sandbox Code Playgroud)

我理解错误是什么,但是如此微小的教程应用程序如何导致启动超时(R10)?

如何更好地调试这个并修复应用程序以便运行?

Cel*_*lik 9

当您通过heroku部署应用程序时,它不允许您指定端口号
换句话说,您不能将 Web 服务的端口号指定为8000或其他,heroku 在运行时决定端口号。
因此,您不能使用以下代码:

    log.Fatal(http.ListenAndServe(":8000", router))
Run Code Online (Sandbox Code Playgroud)

您可以做的是获取heroku 的运行时端口。
简而言之,只需使用以下代码

    log.Fatal(http.ListenAndServe(":" + os.Getenv("PORT"), router))
Run Code Online (Sandbox Code Playgroud)


Dam*_*IEU 6

您的应用需要收听所有网络连接.如果它只侦听localhost,heroku的进程观察程序将无法检测到您绑定了端口,也无法向您的应用程序发送请求.

这意味着代替:

http.ListenAndServe("127.0.0.1:"+port, nil)
Run Code Online (Sandbox Code Playgroud)

你需要打电话:

http.ListenAndServe(":"+port, nil)
Run Code Online (Sandbox Code Playgroud)

另请参阅heroku入门Go app:https://github.com/heroku/go-getting-started/blob/master/cmd/go-getting-started/main.go#L27