在GAE下使用http.Server时运行时出现紧急情况

时间:2014-05-14 13:12:11

标签: google-app-engine go runtime-error

我的代码在这里: http://play.golang.org/p/RehA28iJtA

为什么当我在浏览器中输入“http://example.com:8080/download”时会显示以下错误?

错误:

the runtime process gave a bad HTTP response: ''

2014/05/14 13:07:50 http: panic serving 127.0.0.1:59525: runtime error: invalid memory address or nil pointer dereference
goroutine 3 [running]:
net/http.func·009()
    /tmp/appengine/go_appengine/goroot/src/pkg/net/http/server.go:1093 +0xae
runtime.panic(0x646520, 0x94ba48)
    /tmp/appengine/go_appengine/goroot/src/pkg/runtime/panic.c:248 +0x106
xflight.Download(0x7fcade6926b8, 0xc21000f6e0, 0xc21005ea90)
    xflight/xflight.go:21 +0x132
net/http.HandlerFunc.ServeHTTP(0x71b6e8, 0x7fcade6926b8, 0xc21000f6e0, 0xc21005ea90)
    /tmp/appengine/go_appengine/goroot/src/pkg/net/http/server.go:1220 +0x40
net/http.(*ServeMux).ServeHTTP(0xc21001e630, 0x7fcade6926b8, 0xc21000f6e0, 0xc21005ea90)
    /tmp/appengine/go_appengine/goroot/src/pkg/net/http/server.go:1496 +0x163
appengine_internal.handleFilteredHTTP(0x7fcade6926b8, 0xc21000f6e0, 0xc21005ea90)
    /tmp/appengine/go_appengine/goroot/src/pkg/appengine_internal/api_dev.go:98 +0x2e2
net/http.HandlerFunc.ServeHTTP(0x6fe040, 0x7fcade6926b8, 0xc21000f6e0, 0xc21005ea90)
    /tmp/appengine/go_appengine/goroot/src/pkg/net/http/server.go:1220 +0x40
net/http.serverHandler.ServeHTTP(0xc21000b640, 0x7fcade6926b8, 0xc21000f6e0, 0xc21005ea90)
    /tmp/appengine/go_appengine/goroot/src/pkg/net/http/server.go:1597 +0x16e
net/http.(*conn).serve(0xc210058380)
    /tmp/appengine/go_appengine/goroot/src/pkg/net/http/server.go:1167 +0x7b7
created by net/http.(*Server).Serve
    /tmp/appengine/go_appengine/goroot/src/pkg/net/http/server.go:1644 +0x28b

2 个答案:

答案 0 :(得分:4)

您无法在App Engine中使用默认的http客户端。您需要在此处使用网址抓取服务https://developers.google.com/appengine/docs/go/urlfetch/
示例:http://play.golang.org/p/Gf-WzLmP09

答案 1 :(得分:0)

在您的示例中,缺少func main()。

请参阅playground example

顺便说一句,在func Download()中 - 您使用的是string而非variable,如果您转到http://127.0.0.1:8080/download - 您将始终获得" resp"。