Config - File based configuration parameters
define-config-param
define-config-path
read-config
local-config-file-name
with-config
8.12

Config - File based configuration parameters🔗ℹ

Anurag Mendhekar

 (require config) package: config

Config is a configuration system for file-based configuration parameters that can be specified as part of the code, but read from a configuration file at run time.

The values provided for the configuration parameters are only partially pre-processed at run-time, but never eval’d, to avoid security issues.

Configuration parameters are typically what would be expected to be provided in the runtime configuration file. They are declared using one of the following macros.

syntax

(define-config-param param-name
  [#:path] [#:required] [#:default-value v]
  [#:on-repeat repeat-fn])
Declares a configuration param with the name param-name. The keyword arguments control how this configuration parameter is read from the configuration file.

The configuration file is a sequence of s-expressions of the form

(param-name param-value)

param-value is a value that is implicitly quoted, unless it is of the form
(env ENV_VAR)
in which case the value is read from the environment variable ENV_VAR as a string.

syntax

(define-config-path param-name
  [#:required] [#:default-value v]
  [#:on-repeat repeat-fn])
This is like define-config-param, but #:path is assumed.

procedure

(read-config fname)  void?

  fname : path-or-string?
Reads the configuration from the file given by fname

A function that returns the standard configuration file path. The path is constructed as follows.
  • Environment variable CONFIG_LOCAL_CFG - The path provided by this environment variable is used as a configuration file. If the path is relative, then it is relative to the current working directory

  • Default - The file local.cfg under (current-directory) is used.

This function is typically used with read-config

syntax

(with-config ((param-name param-val) ...) body ...)

Evaluates body ... after binding each provided param-name to the corresponding param-val. This form can be used to inject values for configuration parameters without a configuration file. This is typically used while running unit tests, so that a test-specific configuration value can be supplied. The value overrides any value found in the configuration file.