无法在Heroku上托管Go后端。

huangapple go评论85阅读模式
英文:

Can't host Go backend on Heroku

问题

我有一个Go应用程序,我想在Heroku上托管。这是我的procfile文件内容:

web: studentData

我正在尝试托管这个项目:https://github.com/ArjunMalhotra07/studentData

这是日志:

2022-10-21T08:47:14.341704+00:00 heroku[web.1]: 状态从崩溃变为启动中
2022-10-21T08:47:15.169264+00:00 heroku[web.1]: 正在使用命令`studentData`启动进程
2022-10-21T08:47:16.764117+00:00 app[web.1]: 2022/10/21 08:47:16 dial tcp 127.0.0.1:3306: connect: connection refused
2022-10-21T08:47:16.955065+00:00 heroku[web.1]: 进程以状态1退出
2022-10-21T08:47:17.025025+00:00 heroku[web.1]: 状态从启动中变为崩溃
2022-10-21T11:44:18.962122+00:00 heroku[web.1]: 状态从崩溃变为启动中
2022-10-21T11:44:19.657482+00:00 heroku[web.1]: 正在使用命令`studentData`启动进程
2022-10-21T11:44:21.125150+00:00 app[web.1]: 2022/10/21 11:44:21 dial tcp 127.0.0.1:3306: connect: connection refused
2022-10-21T11:44:21.306577+00:00 heroku[web.1]: 进程以状态1退出
2022-10-21T11:44:21.749452+00:00 heroku[web.1]: 状态从启动中变为崩溃
2022-10-21T12:25:14.309144+00:00 heroku[web.1]: 状态从崩溃变为启动中
2022-10-21T12:25:15.245316+00:00 heroku[web.1]: 正在使用命令`studentData`启动进程
2022-10-21T12:25:16.869878+00:00 app[web.1]: 2022/10/21 12:25:16 dial tcp 127.0.0.1:3306: connect: connection refused
2022-10-21T12:25:17.061078+00:00 heroku[web.1]: 进程以状态1退出
2022-10-21T12:25:17.121535+00:00 heroku[web.1]: 状态从启动中变为崩溃
2022-10-21T13:47:36.216585+00:00 heroku[router]: 错误代码=H10,描述="应用崩溃",方法=GET,路径="/",主机=student-data-go.herokuapp.com,请求ID=dff4bc20-5ba3-40e9-b70e-be468298c454,转发="103.217.117.139",动态=,服务=,状态=503,字节=,协议=https
2022-10-21T13:47:36.923361+00:00 heroku[router]: 错误代码=H10,描述="应用崩溃",方法=GET,路径="/favicon.ico",主机=student-data-go.herokuapp.com,请求ID=f33ae591-8ee3-434b-999c-7a66c273fb77,转发="103.217.117.139",动态=,服务=,状态=503,字节=,协议=https

我无法确定出错的原因。

请告诉我是否还需要指定其他内容以找到问题的根源。

英文:

I have a go application that I want to host on Heroku. This is in my procfile :

web: studentData

I am trying to host this project: https://github.com/ArjunMalhotra07/studentData

These are the logs :

2022-10-21T08:47:14.341704+00:00 heroku[web.1]: State changed from crashed to starting
2022-10-21T08:47:15.169264+00:00 heroku[web.1]: Starting process with command `studentData`
2022-10-21T08:47:16.764117+00:00 app[web.1]: 2022/10/21 08:47:16 dial tcp 127.0.0.1:3306: connect: connection refused
2022-10-21T08:47:16.955065+00:00 heroku[web.1]: Process exited with status 1
2022-10-21T08:47:17.025025+00:00 heroku[web.1]: State changed from starting to crashed
2022-10-21T11:44:18.962122+00:00 heroku[web.1]: State changed from crashed to starting
2022-10-21T11:44:19.657482+00:00 heroku[web.1]: Starting process with command `studentData`
2022-10-21T11:44:21.125150+00:00 app[web.1]: 2022/10/21 11:44:21 dial tcp 127.0.0.1:3306: connect: connection refused
2022-10-21T11:44:21.306577+00:00 heroku[web.1]: Process exited with status 1
2022-10-21T11:44:21.749452+00:00 heroku[web.1]: State changed from starting to crashed
2022-10-21T12:25:14.309144+00:00 heroku[web.1]: State changed from crashed to starting
2022-10-21T12:25:15.245316+00:00 heroku[web.1]: Starting process with command `studentData`
2022-10-21T12:25:16.869878+00:00 app[web.1]: 2022/10/21 12:25:16 dial tcp 127.0.0.1:3306: connect: connection refused
2022-10-21T12:25:17.061078+00:00 heroku[web.1]: Process exited with status 1
2022-10-21T12:25:17.121535+00:00 heroku[web.1]: State changed from starting to crashed
2022-10-21T13:47:36.216585+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=student-data-go.herokuapp.com request_id=dff4bc20-5ba3-40e9-b70e-be468298c454 fwd="103.217.117.139" dyno= connect= service= status=503 bytes= protocol=https
2022-10-21T13:47:36.923361+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=student-data-go.herokuapp.com request_id=f33ae591-8ee3-434b-999c-7a66c273fb77 fwd="103.217.117.139" dyno= connect= service= status=503 bytes= protocol=https

I can't make out whats wrong.

Please let me know if anything else needs to be specified to get to the root of the issue

答案1

得分: 2

检查你与MySQL的连接。错误明确表示存在连接到数据库的问题。在你的GitHub存储库中,我找到了以下内容:

db, err = sql.Open("mysql","aman:Mysql_Witcher7%@tcp(127.0.0.1:3306)/studentInfo")

你应该将127.0.0.1(即localhost)更改为指向你的生产数据库主机的某个环境变量。

英文:

Check you connection to MySql. The error clearly says that there is a problem connecting to the db. Inside your github repo I've found this:

db, err = sql.Open("mysql","aman:Mysql_Witcher7%@tcp(127.0.0.1:3306)/studentInfo")

You should change 127.0.0.1 which is localhost to some env variable that points to your production db host.

huangapple
  • 本文由 发表于 2022年10月21日 15:10:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/74149960.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定