Utilities for managing server configuration via EDN files.
The general design requirements of this support are that you should be able to:
So the basic operation is that you create a default EDN file and one or more environment files (e.g.
dev.edn
, prod.edn
, joes-test-env.edn
, etc. You can then use a combination of runtime parameters,
JVM properties, and environment variables to end up with your runtime configuration.
See load-config!
for more detailed usage.
Utilities for managing server configuration via EDN files. The general design requirements of this support are that you should be able to: * Specify your configuration as EDN. * Specify a reasonable set of server config values as "defaults" so that specific environments can override just what matters. * Override the defaults by deep-merging an environment-specific config file over the defaults. * Specify individual overrides via environment variables. ** Support rich data types from environment variables, like maps, numerics, etc. So the basic operation is that you create a default EDN file and one or more environment files (e.g. `dev.edn`, `prod.edn`, `joes-test-env.edn`, etc. You can then use a combination of runtime parameters, JVM properties, and environment variables to end up with your runtime configuration. See `load-config!` for more detailed usage.
(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 from CLASSPATH (default config/defaults.edn), 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-path
option:
java -Dconfig=/usr/local/etc/app.edn ...
allowing you to affect a packaged JAR application.
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 from CLASSPATH (default config/defaults.edn), 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-path` option: ``` java -Dconfig=/usr/local/etc/app.edn ... ``` allowing you to affect a packaged JAR application. 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