【发布时间】:2020-02-16 13:52:33
【问题描述】:
我已经使用 Google App Engine Go 进行了一段时间的开发,但我已经有一年没有接触过它了。我尝试将我的应用程序从“go1”(1.9?)更新为“go111”,但我目前遇到了一些奇怪的错误,但没有任何解释发生了什么。
错误包括:
The request failed because the instance could not start successfullyContainer called exit(1).500 Internal server error- 等
这些都没有指向我的代码中任何会出错的特定行,也没有解释任何更有意义的东西......
我猜这个错误是由于我在 golang 版本之间升级造成的。我不得不将app 包更改为main,向应用程序添加main 函数,将appengine 包更新到较新版本,更新gsuite 应用程序,添加云编译小部件,更改app.yaml 脚本从 go 到 auto 等。
总而言之,我迷路了。 A Similar SE question yielded no good answers。 Someone else suggested app.yaml might be at fault, so here is mine:
runtime: go111
handlers:
- url: /static
static_dir: static
- url: /res
static_dir: res
- url: /update
script: auto
secure: always
login: admin
- url: /.*
script: auto
secure: always
login: optional
调试控制台日志非常无用:
主文件看起来基本上是这样的:
package main
import (
"fmt"
"google.golang.org/appengine"
"html/template"
"log"
"net/http"
)
var MainTemplate *template.Template
func main() {
http.HandleFunc("/", hello)
var err error
MainTemplate, err = template.ParseFiles("html/main.html")
if err != nil {
log.Printf("ERROR! %v\n", err.Error())
panic(err)
}
log.Printf("Hello world!\n")
}
func hello(w http.ResponseWriter, r *http.Request) {
c := appengine.NewContext(r)
//................................//
MainTemplate.Execute(w, nil)
}
还有什么可能吗?
【问题讨论】:
-
您的代码很可能崩溃了。添加来自 Stackdriver 的错误消息以及您的代码。
-
@JohnHanley 添加了日志,以及基本代码。主函数似乎没有崩溃,没有错误指向任何错误...
-
@ThePiachu 您似乎错过了对 http.ListenAndServe 的调用。看看go111 getting started page 中的 helloworld.go 示例。否则,您的应用将退出而不会监听任何请求(或者,您似乎可以根据 migration guide 调用 appengine.Main)。
-
您发布的代码以前无法在 App Engine 中运行。您的代码启动、处理模板并退出。未启动任何 Web 服务器进程。
-
@JohnHanley 是的,那个函数曾经是
init(),但后来 appengine 告诉我没有main包和main()函数,所以我只是将 init 切换到 main。我想我的头脑已经忽略了示例中的 ListenAndServe,因为它嵌套在日志中...github.com/GoogleCloudPlatform/golang-samples/blob/master/…
标签: google-app-engine go google-cloud-platform runtime