Config - File based configuration parameters
(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])
The configuration file is a sequence of s-expressions of the form
(param-name param-value)
(env ENV_VAR)
#:path - The presence of this keyword indicates that the configuration parameter is expected to be a path. The configuration parameter will be expanded using expand-user-path as soon as it is read.
#:required - The presence of this keyword indicates that the configuration parameter must be provided in the config file. A runtime exception is thrown if the parameter is not found.
#:default-value v - If this configuration parameter is not found in the configuration file, then the default value provided by v is assumed.
- #:on-repeat repeat-fn - When a configuration parameter is read from the file, only its last value is used. If, however, a repeat-fn is provided using #:on-repeat, the value read from the file is invoked on repeat-fn. This function can then be used to accumulate values. For example
(define-config-param repeated-param #:default-value '("some-initial-value") #:on-repeat (λ (val) (cons val (repeated-param)))) If the config file then contains(repeated-param "another-value") Then, the value read will be("another-value" "some-initial-value")
syntax
(define-config-path param-name [#:required] [#:default-value v] [#:on-repeat repeat-fn])
procedure
(read-config fname) → void?
fname : path-or-string?
procedure
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.
syntax
(with-config ((param-name param-val) ...) body ...)