简体   繁体   English

使用环境变量将值传递给App Engine上的Go应用程序

[英]Passing values to a Go application on App Engine with Environment variables

According to the docs, you just have to include them in the app.yaml file https://cloud.google.com/appengine/docs/go/config/appconfig#Go_app_yaml_Defining_environment_variables 根据文档,您只需要将它们包含在app.yaml文件https://cloud.google.com/appengine/docs/go/config/appconfig#Go_app_yaml_Defining_environment_variables中

So I did that like this: 所以我这样做是这样的:

env_variables:
    DEVDOT_OAUTH_CLIENT_ID: 'xxxxx'
    DEVDOT_OAUTH_CLIENT_SECRET: 'xxxxxx'

But when my application runs, it doesn't get these values. 但是,当我的应用程序运行时,它不会获得这些值。 I'm running on a MVM runtime so I removed my init() function and tried calling os.Getenv() from both main() and from a handler I had assigned to the /_ah/start path. 我在MVM运行时上运行,因此删除了init()函数,并尝试从main()和我分配给/ _ah / start路径的处理程序中调用os.Getenv()。

Any ideas? 有任何想法吗?

As how to set environment variables on google appengine? 至于如何在Google Appengine上设置环境变量? explains, "environment variables are not ready until all the init functions are run and I would say same might be applying to the global variable declaration too. It works from a function because by that time environment variables are set". 解释说:“在运行所有init函数之前,环境变量还没有准备好,我想说的是环境变量也可能同样适用于全局变量声明。它可以从一个函数开始工作,因为那时已设置了环境变量”。

You appear to be saying otherwise -- can you try the example code at the other QI pointed to, which was working when that Q was answered, and tell us what you observe instead? 您似乎在说其他话-您可以尝试使用其他QI指出的示例代码,该Q在回答Q时起作用,然后告诉我们您观察到的是什么?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM