View Source ConfigHelpers (config_helpers v1.1.0)
Module to be imported by runtime.exs
to allow accessing the get_env
function.
Note that functions of this module are not supposed to be called by regular application code since they use
Config.config_env()
which is only possible while reading config files.
Link to this section Summary
Link to this section Functions
Read configuration from an environment variables while providing defaults for some envs.
Defaults can be given as keyword list or single value (equivalent to default: <value>
). If the given key
is
not set in the environment (and not empty, see allow_empty
), default keys are checked in the following order:
- Current env, e.g.
:dev
,:test
or:prod
:non_prod
, if current env is:dev
or:test
:default
If no value can be found, ConfigHelpers.EnvError
is raised.
The following options can be added to the defaults list:
as:
Typecast values to:integer
or:boolean
- For
:boolean
, the following values are considered truthy:["true", "True", "TRUE", "yes", "YES", "t", "T", "1"]
- For
:integer
, passing a value that fails conversion usingString.to_integer/1
causesArgumentError
to be raised.
- For
allow_empty:
Whether to accept empty strings as being set. By default, empty strings don't count as being set.
3-arity clause needed to support single default value for all envs together with options list. See get_env/2
for
documentation.