问题描述
我使用在Go中使用GAE应用程序。我需要能够设置 MARTINI_ENV
环境变量来告诉martini它应该使用生产设置进行初始化。根据Python文档。我在中没有看到任何提及,但我是猜测它应该是相同的。
I've got a GAE application in Go using martini. I need to be able to set the MARTINI_ENV
environment variable to tell martini that it should initialize with production settings. According to the Python docs you can set environment variables in the app.yaml. I didn't see any mention of this in the Go docs, but I'm guessing it should work the same.
我需要能够将 MARTINI_ENV
环境变量设置为 production
,但是我只想在生产时(例如!appengine.IsDevAppServer()
)这样做。有没有什么办法可以告诉 app.yaml
只能在非开发服务器上运行?
I need to be able to set the MARTINI_ENV
environment variable to production
, but I only want to do that when I'm actually in production (i.e. !appengine.IsDevAppServer()
). Is there any way to tell app.yaml
to only do this in running on the non-dev server?
推荐答案
Go中的GAE没有设置环境变量的概念,因为它们不会在您的GAE实例中共享。
GAE in Go has no concept for setting environment variables since these won't be shared across your GAE instances.
由于 martini.Env
是一个导出变量,尽管您可以使用自己的逻辑对其进行设置。有多种方法可以做到这一点:
Since martini.Env
is an exported variable though you are able to set it using your own logic. There are multiple ways to do this:
- 默认设置
martini.Env
生产当> MARTINI_ENV
不存在时 将您自己的config.yaml
添加到您的repo,解析它并从那里设置martini.Env
使用类似及其读取
函数,它将读取您的dotfile文件,而不是将它加载到env中。
- Default setting
martini.Env
to production whenMARTINI_ENV
is not present - Add your own
config.yaml
to your repo, parse it and setmartini.Env
from there - Use a library like godotenv with its
Read
function, which will read your dotfile instead of loading it into the env.
这篇关于如何设置GAE环境特定的环境变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!