Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/coingaming/ex_env
https://github.com/coingaming/ex_env
Last synced: about 15 hours ago
JSON representation
- Host: GitHub
- URL: https://github.com/coingaming/ex_env
- Owner: coingaming
- Created: 2018-04-11T12:39:41.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-03-07T18:12:41.000Z (over 1 year ago)
- Last Synced: 2024-03-15T08:22:57.657Z (8 months ago)
- Language: Elixir
- Size: 29.3 KB
- Stars: 8
- Watchers: 38
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# ExEnv
Tool provides support of Elixir terms in system env variables.
For security reasons only literals/terms are allowed in configs (no functions, macros, modules etc).
I very recommend to combine this tool with [BootEnv](https://github.com/coingaming/boot_env).# Installation
```
mix archive.install hex ex_env 0.3.2 --force
```# Usage
For every OTP application, default system variable name is **<UPPER_CASE_OTP_APP>_CONFIG**. Example:
### OS
```
export BEST_APP_CONFIG=" \
[ \
{ \
BestApp.Repo, \
[ \
adapter: Ecto.Adapters.Postgres, \
url: \"ecto://postgres:postgres@localhost/best_app\", \
pool_size: 10 \
] \
}, \
{ \
BestApp.Endpoint, \
[ \
http: [port: 4001], \
server: true \
] \
}, \
{ \
:workers_pool_size, \
100 \
} \
] \
"
```### config.exs
```elixir
use ExEnv # put this line to the bottom of file
```### source code
```elixir
iex> Application.get_env(:best_app, :workers_pool_size)
100
iex> Application.get_env(:best_app, BestApp.Repo)
[
adapter: Ecto.Adapters.Postgres,
url: "ecto://postgres:postgres@localhost/best_app",
pool_size: 10
]
```### external applications
By default **use ExEnv** expression allows to use system-variable based configs for:
- main OTP application of project
- all project dependencies
- :logger OTP applicationIf you need to configure other OTP application - you can use **ExEnv.config** macro manually in **config.exs** (or other config) file
```elixir
use ExEnv
ExEnv.config(:other_app)
ExEnv.config(:other_app, "CUSTOM_ENV_VAR")
```