gpt4 book ai didi

google-app-engine - 在托管虚拟机的本地开发环境中运行 Web 应用程序时出现 appengine.NewContext 错误

转载 作者:IT王子 更新时间:2023-10-29 02:23:57 25 4
gpt4 key购买 nike

我正在尝试在我的开发环境中使用本地托管虚拟机运行应用引擎的演示之一。当代码尝试为请求创建新上下文 (appengine.NewContext(r)) 时,请求会因 panic 而失败:

func handle(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/" {
http.NotFound(w, r)
return
}

c := appengine.NewContext(r)
log.Infof(c, "Serving the front page.")
tmpl.Execute(w, time.Since(initTime))
}

appengine.NewContext(r) 产生此错误:

2015/05/30 01:01:27 appengine: NewContext passed an unknown http.Request 
2015/05/30 01:01:27 http: panic serving 192.168.59.3:51889: appengine: NewContext passed an unknown http.Request
goroutine 115 [running]:
net/http.func·011()
/usr/local/go/src/net/http/server.go:1130 +0xbb
log.Panic(0xc2080c6b10, 0x1, 0x1)
/usr/local/go/src/log/log.go:307 +0xb9
google.golang.org/appengine/internal.WithContext(0x7f7072110508, 0xc20800a380, 0xc208031110, 0x0, 0x0)
google.golang.org/appengine/internal/api.go:247 +0x158
google.golang.org/appengine.WithContext(0x7f7072110508, 0xc20800a380, 0xc208031110, 0x0, 0x0)
google.golang.org/appengine/appengine.go:35 +0x4e
google.golang.org/appengine.NewContext(0xc208031110, 0x0, 0x0)
google.golang.org/appengine/appengine.go:28 +0x7f
main28149.handle(0x7f70721103d0, 0xc208062d20, 0xc208031110)
helloworld.go:28 +0x8f
net/http.HandlerFunc.ServeHTTP(0x8662e0, 0x7f70721103d0, 0xc208062d20, 0xc208031110)
/usr/local/go/src/net/http/server.go:1265 +0x41

net/http.(*ServeMux).ServeHTTP(0xc208038e40, 0x7f70721103d0, 0xc208062d20, 0xc208031110)
/usr/local/go/src/net/http/server.go:1541 +0x17d
net/http.serverHandler.ServeHTTP(0xc2080600c0, 0x7f70721103d0, 0xc208062d20, 0xc208031110)
/usr/local/go/src/net/http/server.go:1703 +0x19a
net/http.(*conn).serve(0xc208062c80)
/usr/local/go/src/net/http/server.go:1204 +0xb57
created by net/http.(*Server).Serve
/usr/local/go/src/net/http/server.go:1751 +0x35e

Dockerfile 是:

FROM gcr.io/google_appengine/go-compat
RUN rm -rf /goroot && mkdir /goroot && curl https://storage.googleapis.com/golang/go1.4.2.linux-amd64.tar.gz | tar xvzf - -C /goroot --strip-components=1
ADD . /app
RUN /bin/bash /app/_ah/build.sh

docker 镜像中似乎没有正确设置 appengine 环境。

如果有任何关于如何解决此问题的建议,我将不胜感激。

谢谢!

最佳答案

来自 Go App Engine for Managed VMs

appengine.Context has been replaced with the Context type from golang.org/x/net/context.

关于google-app-engine - 在托管虚拟机的本地开发环境中运行 Web 应用程序时出现 appengine.NewContext 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30579816/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com