猿问

在 Heroku 上部署 Go 应用程序后面临的问题

我已经在 Heroku 上部署了 Go 应用程序,但是在点击 url 时......它没有给出正确的响应。Heroku 日志看起来像这样:


2015-06-27T10:43:06.839094+00:00 heroku[web.1]: Starting process with command `FlickrImage`

2015-06-27T10:43:08.998400+00:00 heroku[web.1]: State changed from starting to crashed

2015-06-27T10:43:08.998400+00:00 heroku[web.1]: State changed from crashed to starting

2015-06-27T10:43:08.985737+00:00 heroku[web.1]: Process exited with status 0

2015-06-27T10:43:10.795684+00:00 heroku[web.1]: Starting process with command `FlickrImage`

2015-06-27T10:43:13.837301+00:00 heroku[web.1]: Process exited with status 0

2015-06-27T10:43:13.850141+00:00 heroku[web.1]: State changed from starting to crashed

2015-06-27T10:44:41.914412+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/Index" host=morning-ridge-1365.herokuapp.com request_id=89d2e794-a725-4ddf-b437-dbcbd988428c fwd="202.12.83.44" dyno= connect= service= status=503 bytes=

FlickrImage 是我的 go 文件,我创建了一个包含“web: FlickrImage”的 Procfile


编辑:FlickrImageServer 代码:


package main


import (

    "encoding/json"

    "fmt"

    "io/ioutil"

    "log"

    "net/http"

    "os"

    "reflect"

    "strconv"

    "strings"


    "github.com/gorilla/mux"

    "gopkg.in/mgo.v2"

    "gopkg.in/mgo.v2/bson"

)


type imageLinks struct {

    Link     string `bson:"link"`

    Upvote   int    `bson:"upvote"`

    Downvote int    `bson:"downvote"`

}


任何帮助,将不胜感激


牧羊人nacy
浏览 192回答 1
1回答

猛跑小猪

Heroku dynos动态分配端口。您的应用程序可能崩溃了,因为它无法绑定到端口 8080。改变这一行:log.Fatal(http.ListenAndServe(":8080", router))...到这个:    port := ":" + os.Getenv("PORT")    log.Fatal(http.ListenAndServe(port, router))
随时随地看视频慕课网APP

相关分类

Go
我要回答