How to set GAE environment-specific environment variables?
go, google-app-engine
Solution
GAE in Go has no concept for setting environment variables since these won't be shared across your GAE instances.
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:
- Default setting `martini.Env` to production when `MARTINI_ENV` is not present
- Add your own `config.yaml` to your repo, parse it and set `martini.Env` from there
- Use a library like godotenv with its `Read` function, which will read your dotfile instead of loading it into the env.
Problem
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. 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?