package sihl

  1. Overview
  2. Docs
The modular functional web framework

Install

Dune Dependency

Authors

Maintainers

Sources

sihl-queue-0.1.10.tbz
sha256=b264f357c2a65dbed00c3459be76cdd9b21275aeb9d0289634a2050161665211
sha512=b22fa96a3c7fa607df04848b40a0f54890f4f63c519d10ff7fcef8ccf09341731b42ff4decccb4a7e858e138a803c849ee0c5226c514938cdcded2fd80cae4cb

doc/sihl.core/Sihl_core/Configuration/index.html

Module Sihl_core.ConfigurationSource

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

Sourceexception Exception of string
Sourcetype data = (string * string) list

A list of key-value pairs of strings representing the configuration key like SMTP_HOST and a value.

Sourcetype t

The configuration contains configuration data and a configuration schema.

Sourceval make : ?schema:(unit, 'ctor, 'ty) Conformist.t -> unit -> t

make schema data returns a configuration containing the configuration schema and the configuration data.

Sourceval empty : t

empty is an empty configuration without any schema or data.

Sourceval commands : t list -> Command.t list

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.

Sourceval store : data -> unit

store data stores the configuration data.

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.

env_files_path contains the path where the env files are kept. It reads the value of ENV_FILES_PATH. If that environment variable is not set, it goes up directories until a .git, .hg, .svn, .bzr or _darcs directory is found. If none of these are found until / is reached, None is returned.

Sourceval env_files_path : unit -> string option

read_env_file () reads an .env file from the directory given by env_files_path and returns the key-value pairs as data. If SIHL_ENV is set to test, .env.test is read. Otherwise .env is read. If the file doesn't exist or the directory containing the file can't be found, None is returned.

Sourceval read_env_file : unit -> data option Lwt.t
Sourceval read : (unit, 'ctor, 'ty) Conformist.t -> 'ty

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.

Sourceval read_string : string -> string option

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.

Sourceval read_int : string -> int option

read_int key returns the configuration value with key if present. the first call caches the returned value and subsequent calls are fast.

Sourceval read_bool : string -> bool option

read_bool key returns the configuration value with key if present. the first call caches the returned value and subsequent calls are fast.

Sourceval is_testing : unit -> bool

is_testing () returns true if Sihl is running in a test environment, meaning if tests are executing parts of Sihl.

Sourceval is_production : unit -> bool

is_production () returns true if Sihl is running in a production environment.

Sourceval require : t list -> unit

require t raises an exception if the stored configuration doesn't contain the configurations provided by the list of configurations t.

OCaml

Innovation. Community. Security.