Skip to main content
Environment variables live on c.Apps.Envs. Every method takes ctx and the app id first and returns the app’s variables as a squarecloud.EnvVars (a map[string]string). Each snippet below runs on its own inside this program: paste one at a time into main and run goimports (see Running the examples).
Static apps have no environment variables: every method answers 400 STATIC_APP_ENV_NOT_SUPPORTED. A change takes effect on the next restart.

Reading the variables

Adding or updating variables

Envs.Set(ctx, appID, envs) adds the given keys and overwrites the ones that already exist. Other variables are kept. It returns every variable after the change.

Replacing every variable

Envs.Replace(ctx, appID, envs) replaces all variables with the given set. Keys not in the map are removed. It returns the new set.

Removing variables

Envs.Delete(ctx, appID, keys...) removes the given keys and returns the remaining variables. It takes the keys as variadic arguments: pass a slice with keys....

Limits and errors

Next steps

Deploys

Deploy on every push, with a webhook or the GitHub App.

Environment variables API reference

The REST endpoints behind these methods.

Variables from the CLI

The same actions from the terminal.

Read variables in your code

Set variables from the dashboard, CLI or API and read them at runtime.