如何根据项目ID设置变量? [英] How to set variables based on project id?
本文介绍了如何根据项目ID设置变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前有两个项目的App Engine Go应用程序: myapp-prod
和 myapp-staging
。
I currently have an App Engine Go app with 2 projects: myapp-prod
and myapp-staging
.
我希望能够设置某些变量的值,具体取决于应用程序是否在prod或staging中运行。
I'd like to be able to set the value of certain variables depending if the app is running in prod or staging.
有没有一种方法可以让应用程序检测它运行的环境?
Is there a way for the app to detect which environment it is running in?
谢谢
推荐答案
使用环境变量,描述您的应用程序是否处于生产或分期阶段。添加到 app.yml
,
Use an environment variable describing whether your app is on production or staging. Add to app.yml
,
env_variables:
ENVIRONMENT: 'production'
在您的代码中,
In your code,
import "os"
if v := os.Getenv("ENVIRONMENT"); v == "production" {
// You're in production
}
这篇关于如何根据项目ID设置变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文