ConfigZ
Runtime configuration for Elixir applications.
Adapter
Recently only supports Kubernetes ConfigMap. (See: Add ConfigMap data to a Volume)
Dependency
FileSystem (See: System Support)
Installation
Add to your list of dependencies in mix.exs
:
# mix.exs
def deps do
[
{:config_z, "~> 0.3"}
]
end
Ensure :config_z
is started before your application by adding it to :extra_applications
.
# mix.exs
def application do
[
extra_applications: [:config_z, :logger]
]
end
Usage
Prepares callback functions. For example:
def callback(value) do
Application.put_env(:your_application, :your_config, value)
end
Initializes ConfigZ:
:ok =
ConfigZ.init(
name: Your.ConfigZ,
adapter: :config_map,
dir: "/etc/config_map",
callbacks: %{
"YOUR_CONFIG" => &callback/1
}
)
It's best to do this before your supervisor tree is started. The callback function will be called immediately, and also every time the config is changed (created, modified or removed).
Also you can add config keys and callbacks later:
:ok = ConfigZ.watch(Your.ConfigZ, "ANOTHER_CONFIG", &another_callback/1)