godep 지원을 사용하여 Heroku에 Go 애플리케이션을 배포할 때 빌드는 성공했지만 엔드포인트에 액세스하면 "애플리케이션 오류"가 발생합니다.
애플리케이션에서 사용되는 코드는 다음과 같습니다.
import ( "log" "fmt" "net/http" "os" "github.com/gorilla/mux" "github.com/gorilla/context" "gopkg.in/paytm/grace.v1" ) func main() { log.Println("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ CHIT STARTED $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$") log.Println("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$") muxRouter := mux.NewRouter() muxRouter.HandleFunc("/", Articles) http.Handle("/", muxRouter) port := os.Getenv("PORT") if port == "" { port = "9000" // Default port if not specified } err := grace.Serve(":" + port, context.ClearHandler(http.DefaultServeMux)) if err != nil { log.Println("[ERROR GRACEFUL]", err) os.Exit(1) } os.Exit(0) } func Articles(w http.ResponseWriter, r *http.Request) { // vars := mux.Vars(r) w.WriteHeader(http.StatusOK) fmt.Fprintf(w, "Hello") // r.Close = true // w.Header().Set("Content-Type", "application/json") // w.Header().Set("Access-Control-Allow-Origin", "*") /*if r.Method == "OPTIONS" { w.WriteHeader(http.StatusOK) return } if err := fn(w, r); err != nil { log.Println(err) apiObject := ConstructAPIError(http.StatusInternalServerError, ErrGeneral, SysMsgErrGeneral, MsgErrGeneral) SendAPIObject(w, apiObject) return }*/ }
배포 중 Heroku 로그는 다음과 같습니다.
-----> Go app detected -----> Fetching jq... done -----> Fetching stdlib.sh.v8... done -----> Checking Godeps/Godeps.json file. -----> New Go Version, clearing old cache -----> Installing go1.12.6 -----> Fetching go1.12.6.linux-amd64.tar.gz... done -----> Running: go install -v -tags heroku ./... bitbucket.org/michaelchandrag/chit/pkg bitbucket.org/michaelchandrag/chit/vendor/github.com/gorilla/context bitbucket.org/michaelchandrag/chit/vendor/github.com/gorilla/mux bitbucket.org/michaelchandrag/chit/vendor/gopkg.in/tylerb/graceful.v1 bitbucket.org/michaelchandrag/chit/vendor/gopkg.in/paytm/grace.v1 bitbucket.org/michaelchandrag/chit/pkg/util bitbucket.org/michaelchandrag/chit Installed the following binaries: ./bin/chit -----> Discovering process types Procfile declares types -> web -----> Compressing... Done: 7.5M -----> Launching... Released v3 https://michaelchandrag-project.herokuapp.com/ deployed to Heroku
액세스 전후의 애플리케이션 로그 끝점은 다음과 같습니다.
2:47.954106+00:00 heroku[web.1]: Starting process with command `chit` 2019-07-08T05:02:49.413453+00:00 app[web.1]: 2019/07/08 05:02:49 $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ CHIT STARTED $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ 2019-07-08T05:02:49.413476+00:00 app[web.1]: 2019/07/08 05:02:49 $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ 2019-07-08T05:02:49.413647+00:00 app[web.1]: 2019/07/08 05:02:49 starting serve on :9000 2019-07-08T05:03:48.131507+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch 2019-07-08T05:03:48.131595+00:00 heroku[web.1]: Stopping process with SIGKILL 2019-07-08T05:03:48.214979+00:00 heroku[web.1]: State changed from starting to crashed 2019-07-08T05:03:48.193205+00:00 heroku[web.1]: Process exited with status 137 2019-07-08T10:38:59.721224+00:00 heroku[web.1]: State changed from crashed to starting 2019-07-08T10:39:00.359017+00:00 heroku[web.1]: Starting process with command `chit` 2019-07-08T10:39:02.232435+00:00 app[web.1]: 2019/07/08 10:39:02 $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ CHIT STARTED $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ 2019-07-08T10:39:02.232458+00:00 app[web.1]: 2019/07/08 10:39:02 $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ 2019-07-08T10:39:02.232583+00:00 app[web.1]: 2019/07/08 10:39:02 starting serve on :9000 2019-07-08T10:40:00.462841+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch 2019-07-08T10:40:00.462974+00:00 heroku[web.1]: Stopping process with SIGKILL 2019-07-08T10:40:00.555959+00:00 heroku[web.1]: Process exited with status 137 2019-07-08T10:40:00.573427+00:00 heroku[web.1]: State changed from starting to crashed
응용 프로그램이 시작되지만 지정된 포트에 바인딩되지 않아 종료됩니다. 이는 Heroku 로그 메시지에서 분명하게 드러납니다.
2019-07-08T05:03:48.131507+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
이 문제를 해결하려면 웹 서버가 PORT 환경 변수에 지정된 포트에 바인딩되어야 합니다. Heroku에서 HTTP 서버는 Heroku 게이트웨이를 통해 기본 HTTP 및 HTTPS 포트에서 공개적으로 사용할 수 있습니다.
따라서 애플리케이션은 :9000 대신 지정된 포트에 바인딩되어야 합니다.
위 내용은 Heroku에서 Go 앱 배포가 성공했는데 빌드 성공에도 불구하고 애플리케이션에 '애플리케이션 오류'가 표시되는 이유는 무엇입니까?의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!