Config Providers

I am new to the elixir. My task is to read the JSON file on the Application run and store it in the config. I have gone through https://hexdocs.pm/elixir/master/Config.Provider.html

Now my config provider code is

defmodule JSONConfigProvider do
  @behaviour Config.Provider

  # Let's pass the path to the JSON file as config
  def init(path) when is_binary(path), do: path

  def load(config, path) do
    # We need to start any app we may depend on.
    {:ok, _} = Application.ensure_all_started(:jason)

    json = path |> File.read!() |> Jason.decode!()

    json
  end
end

When I try to run this through iex everything looks fine

JSONConfigProvider.load([existing: :config, app: [:appname]],"file_path")

and the next step is Then when specifying your release, you can specify the provider in the release configuration

I don’t have the mix release. Is there any way to store this in the config(dev.ex)?

Just question - are you sure that you need config provider? Maybe running function in start/2 callback during application start would be enough?

2 Likes