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

huangapple go评论105阅读模式
英文:

How to set application wide settings for Go apps in Google App Engine?

问题

谷歌Go应用引擎不支持通过app.yaml文件传递环境变量。在不使用环境变量的情况下,如何设置应用程序范围的设置?


在我具体的情况下,我有一个监视器类型的Webhook应用(https://github.com/jjasonclark/pulltabs),需要处理HMAC解密。因此,我需要一个秘密代码来使其工作。我希望部署多个副本,并具有不同的秘密设置,而不是硬编码。通常,这将是一个环境变量设置。

英文:

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.

答案1

得分: 2

一些可能适合你需求的方法:

  • 配置文件
  • 数据存储

配置文件
在你的项目中添加一个配置文件,并在应用程序初始化时从配置文件中加载设置。Beegae 是这种方法的一个示例。根据你的安全需求,你可以选择将该文件排除在git之外,在部署过程中创建/更新它,甚至考虑为不同情况使用多个配置文件。

数据存储
将设置存储在数据存储中,并在应用程序初始化时加载它们。如果需要在不重新部署应用程序的情况下更改设置,或者多个应用程序共享同一个数据存储并且某些设置的查找逻辑是有意义的,这种方法可能很有用。

英文:

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.

huangapple
  • 本文由 发表于 2015年4月13日 08:00:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/29596071.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定