如何在Google App Engine中为Go应用设置应用范围设置?

The Google App engine for Go does not accept environment variables via the app.yaml file. How do you setup application wide settings without using the environment?


In my specific case I have a watcher type webhook app (https://github.com/jjasonclark/pulltabs) that needs to handle HMAC decryption. So I need to have a secret code for this to work. I would like to deploy many copies with different secret settings, aka not hard coded. Normally this would be an environment variable settings.

Some approaches that may suit depending on your needs:

  • Config file
  • Datastore

Config file Add a config file to your project and load the settings from there on app initialization. Beegae is an example of that approach. Depending on your security needs you might choose to exclude the file from git, create/update it during your deployment process or even consider multiple config files for different cases.

Datastore Store the settings in the datastore and load them on application initialization. This may be useful if settings need to be changed without redeploying the application each time, or multiple applications share the same datastore and some look-up logic for settings makes sense.