dongzhi8487 2015-06-11 16:30
浏览 33

使用App Engine VM时始终获得“ 502错误的网关”

I'm trying to use the app engine VM for my project (env: Go). But am having problems I still haven't been able to resolve after days of searching:

  1. I can't use the package "google.golang.org/appengine" and "google.golang.org/cloud/*" When I deploy my code which contains the above packages I can deploy successfully, but when I access the URL, return always "502 Bad Gateway". If I deploy the code without the above package, all works very well

  2. The problem above happens after an update some of my package. Because I get this problem after I did "go get -u ...", before that all works well

  3. When I see the last commit here (package "google.golang.org/appengine"): https://github.com/golang/appengine/commit/25b8450bec636c6b6e3b9b33d3a3f55230b10812 I don't understand when replace "package helloworld" -> "package main". If I depoy with "package main", I don't know how to access the handler. For example:

func main() { http.HandleFunc("/hello", helloHandler) appengine.Main() }

After deploy, how to test?? Because "my_app.appspot.com/hello" return 404, page not found

I don't know if there is someone else having the same problem. Please help, thanks!!!

  • 写回答

1条回答 默认 最新

  • dongyou9818 2015-08-27 06:52
    关注

    I think you get 502 because of panic on attempt to get Context. You can see it with command sudo docker logs -f gaeapp after connecting to VM instance via ssh.

    It seems that all examples for appengine vm are broken and you should use init(), not main() for initialization:

    package notmainpackage
    
    import (
      "net/http"
    
      "google.golang.org/appengine"
      "google.golang.org/appengine/log"
    )
    
    func init() {
        http.HandleFunc("/", handle)
        appengine.Main()
    }
    
    func handle(w http.ResponseWriter, r *http.Request) {
       ctx := appengine.NewContext(r)
       log.Infof(ctx, "got appengine context")
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统