json_confix v0.1.0 API Reference
Modules
This module provides an implementation of Distilery's configuration provider behavior that changes runtime config tuples for the value.
Usage
Add the following to your rel/config.exs
release :myapp do
# ...snip...
set config_providers: [
JsonConfix.Provider
]
end
This will result in JsonConfix.Provider
being invoked during boot, at which point it
will evaluate the current configuration for all the apps and replace the config tuples when needed, persisting it in the configuration.
Config tuples
The config tuple always start with :json
, and can have some options as keyword, the syntax are like this:
{:json, env_name}
{:json, env_name, opts}
The available options are:type
: Type to cast the value, one of:string
,:integer
,:atom
,:boolean
. Default to:string
default
: Default value if the key is not persent in the JSON file. Default nonil
transform
: Function to transform the final value, the syntax is {Module, :function}required
: Set to true if this key is not persent in the JSON file, if not setted it will raise an error. Default nofalse
For example:{:json, "MYSQL_PORT", type: :integer, default: 3306}
{:json, "ENABLE_LOG", type: :boolean, default: false}
{:json, "HOST", transform: {MyApp.UrlParser, :parse}}
If you need to store the literal values{:json, term()}
,{:json, term(), Keyword.t()}
, you can use{:json, :literal, term()}
to disable JsonConfix config interpolation. For example:{:json, :literal, {:json, "HOST}}
Exceptions
Error custom exception for JsonConfix provider