appengine
appengine copied to clipboard
v2: Expose internal.handleHTTP or otherwise make it easier to construct GAE Context from existing code
Since the deprecation of go111 runtime we've migrated a substantial amount of code to be "a regular Go server code using Cloud libraries", not linking to Appengine libraries at all. In particular this code manages its own http.Server via a shared package. One reason is support for best-effort graceful shutdowns, since this same code (being "a regular Go server code") also runs in Kubernetes.
But GAE Mail has never been replaced with a Cloud API. Now that it is "undeprecated" (per release notes) we'd like to use it from our new code. But the only way to get a working GAE context.Context is by installing handlers into http.DefaultServerMux and using appengine.Main(). This doesn't interoperate with existing non-GAE code that doesn't use the global mux. Also it is impossible to do best-effort graceful shutdowns (which GAE Second Gen technically supports: it sends SIGTERM and waits a bit for the process to exit).
Please consider either exposing internal.handleHTTP or introducing something like appengine.NewRootContext(req *http.Request) so that existing servers that manage their own http.Server have a way to get a valid GAE context for a request.
Note: there's appengine.NewContext already, but it assumes the http.Request came from the internal.handleHTTP and thus doesn't work in general. It just does req.Context().