package helloworld
import (
"fmt"
"net/http"
"appengine"
"appengine/user"
)
func init() {
fmt.Print("hello")
http.HandleFunc("/", handler)
}
func handler(w http.ResponseWriter, r *http.Request) {
c := appengine.NewContext(r)
u := user.Current(c)
if u == nil {
url, err := user.LoginURL(c, r.URL.String())
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.Header().Set("Location", url)
w.WriteHeader(http.StatusFound)
return
}
fmt.Fprintf(w, "Hello, %v!", u)
}
抛出以下错误goapp serve
output
(saucy)adam@localhost:~/projects/ringed-land-605/default$ goapp serve -host 0.0.0.0 .
INFO 2014-06-08 23:57:47,862 devappserver2.py:716] Skipping SDK update check.
INFO 2014-06-08 23:57:47,877 api_server.py:171] Starting API server at: http://localhost:48026
INFO 2014-06-08 23:57:47,923 dispatcher.py:182] Starting module "default" running at: http://0.0.0.0:8080
INFO 2014-06-08 23:57:47,925 admin_server.py:117] Starting admin server at: http://localhost:8000
ERROR 2014-06-08 23:57:48,759 http_runtime.py:262] bad runtime process port ['hello46591\n']
删除fmt.Print()
解决了这个问题。我的问题是为什么会发生这种情况?
当启动运行时进程时,Go开发服务器 https://developers.google.com/appengine/docs/go/tools/devserver(在 App Engine Go SDK 中)正在读取 helloworld 中找到的单行响应init
.
这修改了_start_process_flavor
标记在http_runtime.py
;因此,HTTP 运行时会尝试读取该行以了解要侦听的端口的方向。
读取启动进程文件中预期的单行响应。 [...] START_PROCESS_FILE 风格使用运行时实例的文件来报告它正在侦听的端口。
在这种情况下,hello
不是一个有效的监听端口。
尝试使用 Go 的log http://golang.org/pkg/log/包代替:
log.Print("hello")
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)