A Gleam configuration library.
Relys on erlang's persistent_terms.
{deps, [
{config, {git, "https://github.com/mpope9/config"}}
]}.
This is powered by a gen_server, but configs are parsed and stored independently. The gen_server is for safety and to optimize puts.
Configuration:
[test1.test2]
test3 = true
Usage:
import gleam/config
import gleam/dynamic
config.new() // Parses the config and stores it.
config.start() // Starts the config server.
config.get("test1.test2.test3") // Access.
|> expect.equal(_, Ok(True))
config.get_default("not.existing", False)
|> expect.equal(_, Ok(False))
Updates to the config can have a performance penalty, due to persistent_term
s being optimized for reads over writes. So it is preffered to update configs in batches. This is done through passing a map to the config module. Values in the map will override existing configuration values.
import gleam/map
let new_config =
map.new
|> map.insert(_, "key1", "value1")
|> map.insert(_, "Ricky Booby", "Cal Naughton Jr.")
config.put_batch(new_config)
To update a single value, the following api is provided, although its use is discouraged if multiple updates need to be made. It will also override an existing value.
config.put("key1", "value1")
Getting the whole configuration is supported.
config.get_config()
Parses toml files and stores them as strings. At this time, only string key are supported. An example:
[test1.test2]
test3 = true
This config's key is transalted to the Gleam string:
"test1.test2.test3"
and returns an atom value when accessed.
The default config value lives at config/config.toml
for a project.
To use a seperate config file, you can set the environment variable GLEAM_CONFIG
.
- Ability to add to the Gleam supervision tree.
- Gleam gen_server implementation.
- Replace toml library with Gleam implementation (file read, etc.)
# Build the project
rebar3 compile
# Run the eunit tests
rebar3 eunit
# Run the Erlang REPL
rebar3 shell