CJPoll / epa

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

Home Page:https://hex.pm/packages/epa

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.

About

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

https://hex.pm/packages/epa


Languages

Language:Elixir 100.0%