https://github.com/renderedtext/ex-config
Simple Elixir configuration managment.
https://github.com/renderedtext/ex-config
Last synced: 8 months ago
JSON representation
Simple Elixir configuration managment.
- Host: GitHub
- URL: https://github.com/renderedtext/ex-config
- Owner: renderedtext
- License: mit
- Created: 2016-11-05T16:58:47.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2018-04-01T20:23:03.000Z (about 8 years ago)
- Last Synced: 2025-04-17T12:43:30.067Z (about 1 year ago)
- Language: Elixir
- Homepage:
- Size: 6.84 KB
- Stars: 6
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Config
Fetch configuration values from the application's configuration or
from the environment if it is provided.
Based on [@bitwalker's gist](https://gist.github.com/bitwalker/a4f73b33aea43951fe19b242d06da7b9).
## Installation
``` elixir
def deps do
[
{:config, github: "renderedtext/ex-config"}
]
end
```
## Usage
Fetch configuration values:
``` elixir
case Config.get(:my_app, :foo) do
{:ok, value} -> IO.puts value
{:error, _} -> IO.puts "Configuration value not set"
end
```
Providing a default value:
``` elixir
{:ok, value} = Config.get(:my_app, :foo, default: "bar")
```
Use the `Config.get!` to raise an exception if the variable is not provided:
``` elixir
value = Config.get!(:my_app, :foo)
```
To fetch an integer:
``` elixir
{:ok, value} = Config.get_integer(:my_app, :foo)
# with default value
{:ok, value} = Config.get_integer(:my_app, :foo, 3)
# raise exception
value = Config.get_integer!(:my_app, :foo)
```
To fetch a boolean:
``` elixir
{:ok, value} = Config.get_boolean(:my_app, :foo)
# with default value
{:ok, value} = Config.get_boolean(:my_app, :foo, true)
# raise exception
value = Config.get_boolean!(:my_app, :foo)
```