Lamina.Provider.Env (lamina v0.2.2)
A configuration provider for retrieving information from the UNIX process environment.
Allows you to use process enviroment variables as application configuration.
This is a very simple wrapper around System.get_env/2
. See the Elixir core
documentation for more information.
Name mangling
We use a process called "name mangling" to convert an atom configuration key
into the name of an environment variable. The default mangler
(name_mangler/2
) converts the configuration key into UPPER_SNAKE_CASE with
an optional prefix.
Should you need to you can define your own mangler function and pass it as the
:mangler
option to this provider.
Examples
Given the following environment variables:
Name | Value |
---|---|
PHOENIX_HTTP_PORT | 4000 |
BIND_ADDR | 0.0.0.0 |
We can retrieve the configurations from the environment:
iex> {:ok, state, _} = Env.init(prefix: "PHOENIX")
...> {:ok, "4000", :volatile, _state} = Env.fetch_config(:http_port, state)
iex> {:ok, state, _} = Env.init([])
...> {:ok, "0.0.0.0", :volatile, _state} = Env.fetch_config(:bind_addr, state)
Link to this section Summary
Functions
The default name mangler for environment variables.
Link to this section Types
lifetime_option()
Specs
lifetime_option() :: {:lifetime, Lamina.Provider.lifetime()}
mangler_option()
Specs
option()
Specs
option() :: prefix_option() | mangler_option() | refresh_period_option() | lifetime_option()
options()
Specs
options() :: [option()]
prefix_option()
Specs
prefix_option() :: {:prefix, String.t()}
refresh_period_option()
Specs
refresh_period_option() :: {:refresh_period, pos_integer()}
state()
Specs
state() :: %{ :mangler => (atom(), any() -> String.t()), :refresh_period => pos_integer(), :lifetime => Lamina.Provider.lifetime(), optional(:prefix) => String.t() }
Link to this section Functions
name_mangler(config_key, arg2)
Specs
The default name mangler for environment variables.
Converts the configuration key into an upper-case underscored string, optionally with a prefix.
Examples:
iex> Env.name_mangler(:http_port, %{})
"HTTP_PORT"
iex> Env.name_mangler(:http_port, %{prefix: "phoenix"})
"PHOENIX_HTTP_PORT"