If you are using App Engine on the Google Cloud Platform (GCP) you shouldn’t be too surprised when receiving an email stating the current version you are using is being deprecated. Chances are you haven’t read Google’s deprecation policy, which also applies to App Engine (listed here). which basically states that if Google decides to upgrade their services and deprecate older version, they can. And will. And you will be forced to follow along. So of course, the email which came on June 27, 2019 should not have come as a surprise to you:
Hello Google App Engine Customer, We’re writing to let you know that Go versions prior to 1.11 are no longer supported on App Engine, and new deployments using these language versions (1.6, 1.8, and 1.9) will not be available starting October 1, 2019.This left about 3 months to upgrade.
How much effort?What does this upgrade exactly mean? Is it just changing some configuration files? Well, yes and no. The migrating guide explains what you need to do. It contains some required and some recommended changes.
Required changesThere are several required changes for upgrading to the go1.11 runtime one needs to do, while keep using the App Engine specific APIs.
App.yamlIn your app.yaml (or service.yaml) the “runtime” should be set to go111 and the “api_version” should be removed. Under the url property the "application_readable: true" should be removed, this applies by default now. Furthermore the "script: _go_app" should be replaced by "script: auto". The “includes” tag is deprecated, but fortunately can still be used. The url handlers “login:admin” can still be used, but is also deprecated and will be unsupported with the go1.12 runtime. You might need to change some more things, but you’ll get clear error messages when deploying your application with “gcloud app deploy [...]”.
Application entrypointYou’ll need to change your application’s entry point. The package must be called “main” and the entrypoint function called “main()” as well. The filename does not matter. At the end of this main() function you’ll need to add “appengine.Main()” if you still want to use App Engine specific APIs. If you don’t, you should read the PORT environment variable and use it to call the http listen and serve method, otherwise your application will not continue running after starting up.
App Engine build tagIn the old runtime one could have two files with identical function names, one with “//build appengine” at the top and another with “//build !appengine”. During the build process one of the files would be built in the App Engine environment, the other while e.g. running unit tests. This functionality is deprecated, which means the file with the App Engine build tag will be completely ignored. There are of course several solutions, our approach was to toggle between an App Engine and a mock function based on the “appengine.IsAppengine()” function. Or maybe even better, to perform the check
os.Getenv("GAE_ENV") == "standard"