The user with no hat
The user with no hat

Reputation: 10846

how to set environment variables on google appengine?

I'm trying to set and use an environment variable on google app engine. My app.yaml file looks as below. However when I use os.Getenv("mytoken") I get an empty string instead the actual value I set. Is it a GAE bug?

api_version: go1
handlers:
- url: /.*
  script: _go_app
env_variables:
  mytoken: '88786d9b9a0359824'

Upvotes: 7

Views: 7469

Answers (3)

Chunliang Lyu
Chunliang Lyu

Reputation: 1750

The feature is now documented here. However, as I have tested just now, it doesn't work on AppEngine. It does work on local server, so don't be fooled..

Edit: It works on Google AppEngine. My previous failure is due to a mistake. Consider this:

import "os"

var consumer = OAuth1Consumer{
    secret: os.Getenv("secret")
}

It does not work if you declare as global variable.

Upvotes: 8

Alex Martelli
Alex Martelli

Reputation: 881555

Unfortunately, the GAE Go runtime does not support environment variable setting in app.yaml -- see for example How to set GAE environment-specific environment variables? and https://groups.google.com/forum/#!msg/google-appengine-go/qzMbZapLyAU/eKOZzZO14qQJ .

The functionality is supported in PHP, per https://cloud.google.com/appengine/docs/php/config/appconfig#PHP_app_yaml_Defining_environment_variables ; Java, per https://cloud.google.com/appengine/docs/java/config/appconfig#Java_appengine_web_xml_System_properties_and_environment_variables ; and Python, per https://cloud.google.com/appengine/docs/python/config/appconfig#Python_app_yaml_Defining_environment_variables .

In the Go runtime for App Engine, however -- see https://cloud.google.com/appengine/docs/go/config/appconfig -- there is simply no equivalent functionality.

I would recommend opening a feature request at https://code.google.com/p/googleappengine/issues/list?can=2&q=language=Go&colspec=ID%20Type%20Component%20Status%20Stars%20Summary%20Language%20Priority%20Owner%20Log (I don't see any equivalent feature request already in the list of 27 open FRs, or else, of course, I would recommend just "starring" the existing FR to register your interest in it).

Upvotes: 2

Logiraptor
Logiraptor

Reputation: 1518

I can't find the docs for that field anywhere. I only see it in the python config, not the Go config. It's likely unavailable for go if you're basing this off of the python docs here

Upvotes: 0

Related Questions