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

时间:2015-06-01 17:42:37

标签: google-app-engine go

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

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环境。

我很感激有关如何解决这个问题的任何建议。

谢谢!

1 个答案:

答案 0 :(得分:0)

来自Go App Engine for Managed VMs

  

appengine.Context已被golang.org/x/net/context中的Context类型替换。