Kungfuig.Backend behaviour (Kungfuig v1.0.1)

View Source

The scaffold for the backend watching the external config source.

Example

defmodule Kungfuig.Backends.EnvTransform do
  @moduledoc false

  use Kungfuig.Backend, report: :logger, imminent: true

  @impl Kungfuig.Backend
  def get(meta) do
    {:ok,
     meta
     |> Keyword.get(:for, [:kungfuig])
     |> Enum.reduce(%{}, &Map.put(&2, &1, Application.get_all_env(&1)))}
  end

  @impl Kungfuig.Backend
  def transform(%{kungfuig: env}) do
    {:ok, for({k, v} <- env, {_, value} <- v, do: {k, value})}
  end
end

Summary

Callbacks

The implementation of the call to remote that retrieves the data

The implementation of the call to remote that retrieves the data under a key specified

The key this particular config would be stored under, defaults to module name

The implementation of error reporting

The transformer that converts the retrieved data to internal representation

Callbacks

get(list)

@callback get([Kungfuig.option()]) :: {:ok, any()} | {:error, any()}

The implementation of the call to remote that retrieves the data

get(list, atom)

@callback get([Kungfuig.option()], atom()) :: {:ok, any()} | {:error, any()}

The implementation of the call to remote that retrieves the data under a key specified

key()

(optional)
@callback key() :: atom()

The key this particular config would be stored under, defaults to module name

report(any)

(optional)
@callback report(any()) :: :ok

The implementation of error reporting

transform(any)

(optional)
@callback transform(any()) :: {:ok, any()} | {:error, any()}

The transformer that converts the retrieved data to internal representation