Dotenvy.env-exclamation-mark
env-exclamation-mark
, go back to Dotenvy module for more information.
Specs
Reads the given system environment variable
and converts its value to the given
type
.
Internally, this behaves like System.fetch_env!/1
: it will raise if a variable is
not set or if empty values are encounted when non-empty values are required.
The conversion is delegated to Dotenvy.Transformer.to!/2
-- see its documentation
for a list of supported types.
Examples
iex> env!("PORT", :integer)
5432
iex> env!("ENABLED", :boolean)
true
Specs
Reads a system environment variable and converts its output or returns a default value.
Use of env!/2
is usually recommended over env!/3
because it creates a stronger contract with
the environment (i.e. your app literally will not start if required env variables are missing)
but there are times where supplying default values is desirable, and the env!/3
function is
appropriate for those situations.
If the given system environment variable
is set, its value is converted to
the given type
. The provided default
value is only used when the system environment
variable is not set; the default
value is returned as-is, without conversion.
This allows greater control of the output.
Although this relies on System.fetch_env/1
, it may still raise an error
if an unsupported type
is provided or if non-empty values are required because
the conversion is delegated to Dotenvy.Transformer.to!/2
-- see its documentation
for a list of supported types.
Examples
iex> env!("PORT", :integer, 5432)
5433
iex> env!("NOT_SET", :boolean, %{not: "converted"})
%{not: "converted"}
iex> System.put_env("HOST", "")
iex> env!("HOST", :string!, "localhost")
** (Dotenvy.Transformer.Error) non-empty value required