/epa

Protect your environment... configuration. For Elixir lang.

Primary LanguageElixir

Epa

Installation

  1. Add epa to your list of dependencies in mix.exs:
```elixir
def deps do
  [{:epa, "~> 0.1.1"}]
end
```

Usage

In your Application's start/2 function, simply do:

defmodule MyApp do
  import EPA

  def start(_, _) do
    required(["ENV_VAR_1", "API_KEY_THING"])
  end
end

Now the app will raise an exception on boot if the env vars aren't correctly set!

Optionally, you can set which env the check is for:

defmodule MyApp do
  import EPA

  def start(_, _) do
    required(["ENV_VAR_1", "API_KEY_THING"], [:dev, :test])
    required(["ENV_VAR_2", "API_KEY_THING"], :prod)
  end
end

What going on?

&EPA.required/1-2 gets the value out with System.get_env, stripping leading or trailing whitespace. If the value is nil or "" (after stripping), then an exception is raised telling you which env vars are missing.