【发布时间】:2019-09-06 03:09:27
【问题描述】:
我在 golang 中创建了一个小型测试应用程序,并试图将其部署到 Google AppEngine,虽然“gcloud app deploy”命令似乎可以工作并且没有报告错误,但当我访问端点时 -> https://XXX.appspot.com/cards 它只是坐在那里,最终给我一个 500 响应,并显示错误(在浏览器中)
Error: Server Error
The server encountered an error and could not complete your request.
Please try again in 30 seconds.
我是 Go golang 和 AppEngine 的新手,但我最近制作了几个可用的应用程序,我完全不知道为什么它不工作。
当我输入“gcloud app logs tail -s default”时,我会看到一些日志条目,例如:
2019-09-06 02:17:31 default[20190905t204717] "GET / HTTP/1.1" 500
2019-09-06 02:17:32 default[20190905t204717] Starting the application...
2019-09-06 02:22:08 default[20190905t212008] "GET / HTTP/1.1" 500
2019-09-06 02:22:08 default[20190905t212008] Starting the application...
2019-09-06 02:22:14 default[20190905t212008] "GET /cards HTTP/1.1" 500
2019-09-06 02:22:17 default[20190905t212008] "GET /cards HTTP/1.1" 500
2019-09-06 02:22:17 default[20190905t212008] Starting the application...
这里是简单的单文件go app“main.go”
package main
import (
"encoding/json"
"fmt"
"github.com/gorilla/mux"
"net/http"
)
func main() {
fmt.Println("Starting the application...")
router := mux.NewRouter()
router.HandleFunc("/cards", GetCardsEndpoint).Methods("GET")
err := http.ListenAndServe(":80", router)
fmt.Println("ERR:", err)
}
func GetCardsEndpoint(response http.ResponseWriter, request *http.Request) {
fmt.Println("API: GetCardsEndpoint() ")
err := json.NewEncoder(response).Encode("cards api here")
fmt.Println("API: GetCardsEndpoint() err:", err )
}
app.yaml
runtime: go111
它应该返回文本:“cards api here”
【问题讨论】:
标签: google-app-engine go gcloud