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:
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
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
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!!!
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")
}