pretty

Thursday 31 January 2019

GoScores: leaderboard on Google Cloud


Simple Leaderboard server, written in Go language and hosted on Google Cloud. Source (Github).

Sample app that uses the leaderboard: Buildris on Google Play


Update: Migrating to Go 1.16 on Google Cloud.

Google Cloud no longer supports Go 1.11 runtime, the migration guide from Google is available.

Appengine google.golang.org/appengine/* packages were removed and google cloud cloud.google.com/go/* packages have to be used instead (or Go standard library packages were applicable).

For example:
google.golang.org/appengine/datastore -> cloud.google.com/go/datastore (from Google cloud library) google.golang.org/appengine/log -> log (from Go standard library package)

Sample diff of migration for GoScores app from 1.11 to 1.16, that uses Google Cloud datastore.

To highlight other migration changes:
  • Port should now be set explicitly
  • Data store API was modified, for example, query.GetAll(() is now dsClient.GetAll().
  • Some functions calls changed, for example RunInTransaction() no longer accepts nil for TransactionOptions. Passing nil would result in 503 Server Error and in logs: “panic serving … nil TransactionOption goroutine [running]:”

To test locally:
  • Credentials should be locally available, run export with a path to the file with key:
    export GOOGLE_APPLICATION_CREDENTIALS="/home/user/Downloads/service-account-file.json"
    Key is available for download in Cloud Console, IAM and Admin -> Service accounts -> Keys tab. https://cloud.google.com/docs/authentication/production
  • go run scores.go
  • check GET response on localhost:8080


To deploy:
Inside app dir call (given google-cloud-sdk directory is one level up) ../google-cloud-sdk/bin/gcloud app deploy

-----
Full logs of app execution and errors are available in Logs Explorer: https://console.cloud.google.com/logs