如何设置GAE环境特定的环境变量? [英] How to set GAE environment-specific environment variables?

查看:139
本文介绍了如何设置GAE环境特定的环境变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用马提尼在Go中使用GAE应用程序。我需要能够设置 MARTINI_ENV 环境变量来告诉martini它应该使用生产设置进行初始化。根据Python文档,您可以在app.yaml中设置环境变量。我在转到文档中没有看到任何提及,但我是猜测它应该是相同的。

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:


  1. 默认设置 martini.Env 生产当> MARTINI_ENV 不存在时 将您自己的 config.yaml 添加到您的repo,解析它并从那里设置 martini.Env 使用类似 godotenv 及其读取函数,它将读取您的dotfile文件,而不是将它加载到env中。

  1. Default setting martini.Env to production when MARTINI_ENV is not present
  2. Add your own config.yaml to your repo, parse it and set martini.Env from there
  3. Use a library like godotenv with its Read function, which will read your dotfile instead of loading it into the env.

这篇关于如何设置GAE环境特定的环境变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆