google-app-engine - 如何根据项目ID设置变量?

标签 google-app-engine go

我目前有一个包含 2 个项目的 App Engine Go 应用程序:myapp-prodmyapp-staging

我希望能够设置某些变量的值,具体取决于应用程序是在生产环境还是暂存环境中运行。

应用程序有没有办法检测它在哪个环境中运行?

谢谢

最佳答案

您可以使用 appengine.AppID() 函数获取应用程序的名称/ID:

// AppID returns the application ID for the current application.
// The string will be a plain application ID (e.g. "appid"), with a
// domain prefix for custom domain deployments (e.g. "example.com:appid"). 
func AppID(c Context) string

并且您可以使用 appengine.IsDevAppServer() 来判断您的应用程序是在开发模式下运行(使用 AppEngine SDK)还是实时运行(在生产中):

// IsDevAppServer reports whether the App Engine app is running in the
// development App Server. 
func IsDevAppServer() bool

或者,您也可以使用 appengine.ServerSoftware(),它包含以上两种信息,合并为一个字符串:

// ServerSoftware returns the App Engine release version.
// In production, it looks like "Google App Engine/X.Y.Z".
// In the development appserver, it looks like "Development/X.Y". 
func ServerSoftware() string

关于google-app-engine - 如何根据项目ID设置变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36184603/

相关文章:

python - 如果我的方法有多个路由注释,我该如何使用 url_for?

google-app-engine - 如何使用自定义域强制执行到 Google App Engine 的 HTTPS 流量?

go - 如何在多个记录处理器之间平衡运动碎片?

go - go get 的 TLS 问题

google-app-engine - 如何更改用于部署到 GAE 的帐户?

java - Google AppEngine maven 应用程序更新

python - 我的本地 App Engine 数据存储在哪里?

go - 使用 getvar 时如何让 Zebra 打印机返回换行符?

json - 无法将对象解码为 []uint8 类型的 Go 值

go - 从字符串列表初始化结构