dptpn06684 2014-06-09 00:02
浏览 54
已采纳

有人可以解释为什么以下gocode无法通过goapp服务失败

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)
}

Throw the following error in 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
']

Removing the fmt.Print() fixes the issue. My question is why does that happen?

  • 写回答

1条回答 默认 最新

  • duanfei1975 2014-06-09 02:32
    关注

    When starting the runtime process, the Go Development Server (in the App Engine Go SDK) is reading the single line response found in your helloworld's init.

    This modifies the _start_process_flavor flag in http_runtime.py; consequently, the HTTP runtime attempts to read the line for direction on which port to listen to.

    Read the single line response expected in the start process file. [...] The START_PROCESS_FILE flavor uses a file for the runtime instance to report back the port it is listening on.

    In this case, hello isn't a valid port to listen on.


    Try using Go's log package instead:

    log.Print("hello")
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 java业务性能问题求解(sql,业务设计相关)
  • ¥15 52810 尾椎c三个a 写蓝牙地址
  • ¥15 elmos524.33 eeprom的读写问题
  • ¥15 使用Java milo连接Kepserver服务端报错?
  • ¥15 用ADS设计一款的射频功率放大器
  • ¥15 怎么求交点连线的理论解?
  • ¥20 软件开发方法学习来了
  • ¥15 微信小程序商城如何实现多商户收款 平台分润抽成
  • ¥15 HC32L176调试了一个通过TIMER5+DMA驱动WS2812B
  • ¥15 关于自相关函数法和周期图法实现对随机信号的功率谱估计的matlab程序运行的问题,请各位专家解答!