Utilities for managing server configuration via EDN files. These functions expect a config/defaults.edn to exist
on the classpath as a definition for server configuration default values. When you call load-config!
it will
deep merge the file you supply with the base defaults to return the 'complete' configuration. When loading
configurations a relative path is evaluated against CLASSPATH and an absolute path against the real filesystem.
The values in the EDN files can be :env/VAR to pull a string from an env variable, and :env.edn/VAR to do a read-string
against the value of an environment variable.
Utilities for managing server configuration via EDN files. These functions expect a config/defaults.edn to exist on the classpath as a definition for server configuration default values. When you call `load-config!` it will deep merge the file you supply with the base defaults to return the 'complete' configuration. When loading configurations a relative path is evaluated against CLASSPATH and an absolute path against the real filesystem. The values in the EDN files can be :env/VAR to pull a string from an env variable, and :env.edn/VAR to do a `read-string` against the value of an environment variable.
(load-config!)
(load-config! {:keys [config-path defaults-path]})
Load a configuration file via the given options.
options is a map with keys:
:config-path
: The path to the file to load (in addition to the addl behavior described below).:defaults-path
: (optional) A relative or absolute path to the default options that should be the basis of configuration.
Defaults to config/defaults.edn
. When relative, will come from resources. When absolute, will come from disk.Reads the defaults, then deep merges the EDN content of an additional config file you specify into that and evaluates environment variable expansions.
You may use a Java system property to specify (override) the config file used:
java -Dconfig=/usr/local/etc/app.edn ...
If no such property is used then config-path MUST be supplied (or this will throw an exception).
Values in the EDN of the form :env/VAR mean to use the raw string value of an environment variable, and
:env.edn/VAR mean to use the read-string
value of the environment variable as that value.
So the classpath resource config/defaults.edn might contain:
{:port 3000
:service :A}
and /usr/local/etc/app.edn
might contain:
{:port :env.edn/PORT}
and a call to (load-config! {:config-path "/usr/local/etc/app.edn"})
on a system with env variable PORT="8080"
would return:
{:port 8080 ;; as an integer, not a string
:service :A}
If your EDN file includes a symbol (which must be namespaced) then it will try to require and resolve it dynamically as the configuration loads.
Load a configuration file via the given options. options is a map with keys: * `:config-path` : The path to the file to load (in addition to the addl behavior described below). * `:defaults-path` : (optional) A relative or absolute path to the default options that should be the basis of configuration. Defaults to `config/defaults.edn`. When relative, will come from resources. When absolute, will come from disk. Reads the defaults, then deep merges the EDN content of an additional config file you specify into that and evaluates environment variable expansions. You may use a Java system property to specify (override) the config file used: ``` java -Dconfig=/usr/local/etc/app.edn ... ``` If no such property is used then config-path MUST be supplied (or this will throw an exception). Values in the EDN of the form :env/VAR mean to use the raw string value of an environment variable, and :env.edn/VAR mean to use the `read-string` value of the environment variable as that value. So the classpath resource config/defaults.edn might contain: ``` {:port 3000 :service :A} ``` and `/usr/local/etc/app.edn` might contain: ``` {:port :env.edn/PORT} ``` and a call to `(load-config! {:config-path "/usr/local/etc/app.edn"})` on a system with env variable `PORT="8080"` would return: ``` {:port 8080 ;; as an integer, not a string :service :A} ``` If your EDN file includes a symbol (which must be namespaced) then it will try to require and resolve it dynamically as the configuration loads.
Not meant for public consumption
Not meant for public consumption
Not meant for public consumption
Not meant for public consumption
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close