package sihl
Install
Dune Dependency
Authors
Maintainers
Sources
sha256=bfa7bde9af02bb83d5ca39d54797b05b43317f033d93d24ca86ca42ff8ef83a1
sha512=6bb8727f65116e8042aa1fb77b3c14851ce5238f7b412adadf0f8e5b52d5310e8f06056c96bf76a82ffd7096753f49b2b0482f41e18ee1ca94310b874fe81bf9
doc/sihl.core/Core/Configuration/index.html
Module Core.Configuration
Source
A module to manage service configurations.
An app’s configuration is everything that is likely to vary between deploys (staging, production, developer environments, etc).
This includes:
- Resource handles to the database, Memcached, and other backing services
- Credentials to external services such as Amazon S3 or Twitter
- Per-deploy values such as the canonical hostname for the deploy
(Source: https://12factor.net/config)
Configuration
A list of key-value pairs of strings representing the configuration key like SMTP_HOST and a value.
The configuration contains configuration data and a configuration schema.
make ?schema data
returns a configuration containing the configuration schema
and the configuration data
.
commands configurations
returns the list of CLI commands given a list of configurations.
Storing configuration
Configuration might come from various sources like .env files, environment variables or as data provided directly to services or the app.
A configuration is a list of key-value string pairs.
Reading configuration
Using the schema validator conformist it is easy to validate and decode configuration values. Conformist schemas can express a richer set of requirements than static types, which can be used in services to validate configurations at start time.
Validating configuration when starting services can lead to run-time exceptions, but they occur early in the app lifecycle. This minimizes the feedback loop and makes sure, that services start only with valid configuration.
read schema
returns the decoded, statically typed version of configuration t
of the schema
. This is used in services to declaratively define a valid configuration.
The configuration data t
is merged with the environment variable and, if present, an .env file.
It fails with Exception
and prints descriptive message of invalid configuration.
read_string key
returns the configuration value with key
if present. The function is memoized, the first call caches the returned value and subsequent calls are fast.
read_int key
returns the configuration value with key
if present. the first call caches the returned value and subsequent calls are fast.
read_bool key
returns the configuration value with key
if present. the first call caches the returned value and subsequent calls are fast.
is_testing ()
returns true if SIHL_ENV is set to testing
.