Confx (confx v0.1.0) View Source

Find and load configuration from files.

Available file types:

  • JSON
  • YAML

Installation

def deps do
  [
    {:confx, "~> 0.1.0"}
  ]
end

Usage

Following the configuration file:

# config.yml
my_app:
  host: "http://localhost"
  port: 400

It's possible to load this config formatted in Elixir maps:

iex(1)> Confx.load("config.yml")
{:ok, %{
  my_app: %{
    host: "http://localhost",
    port: 4000
  }
}}

# Using defaults
iex(2)> Confx.load("config.yml", defaults: [my_app: [method: "POST"]])
{:ok, %{
  my_app: %{
    host: "http://localhost",
    port: 4000,
    method: "POST"
  }
}}

Check out the docs for more info.

Link to this section Summary

Functions

Returns the configuration specified in the given file

Same as load/2 but returns the config map directly, or raises an exception if an error is returned

Link to this section Functions

Specs

load(term(), Keyword.t()) ::
  {:ok, map()}
  | {:error, :file_not_found}
  | {:error, :file_format_not_found}
  | {:error, atom()}

Returns the configuration specified in the given file

Options

The accepted options are:

  • defaults: If some key could not be found, the default will be assumed

Specs

load!(term(), Keyword.t()) :: map()

Same as load/2 but returns the config map directly, or raises an exception if an error is returned