Liking cljdoc? Tell your friends :D

nicheware.platform.utilities.common.config

Supports reading application configuration as a clojure map.

Features include:

  • merging of a global config file, with an environment specific one (eg dev, test, prod)
  • mustache variable substitution in config values. Variables are previously defined config values.
  • mustache function operation on config value.
  • optional parameters to override defaults.

As an example, global configuration, common to every environment, could be defined in resources/app/config.edn

{:env "default"
 :value "common-value"
 :file "{{env}}-file.txt"}

An environment specific config (eg for test) could be defined in env/test/resources/app/env-config.edn.

{:env "test"
 :other "value"}

When the execution environment is setup to include "resources" and "env/test/resources" on the classpath (as would be done when executing tests), then calling (load-config "app") will return:

{:env "test"
 :other "value"
 :value "common-value"
 :file "test-file.txt"}

Variable evaluation is done recursively, on the final merged map until all variables have been evaluated.

Both load-config and load-http-config accept an optional opts map, which can selectively override the following defaults:

{:env-file-name "env-config.edn"
 :common-file-name "config.edn"
 :resolve-vars true}

The opts arguments may also define :common-path or :env-path, which would then be used instead of building up the path from the file name and provided path prefix.

Supports reading application configuration as a clojure map.

   Features include:

   - merging of a global config file, with an environment specific one (eg dev, test, prod)
   - mustache variable substitution in config values. Variables are previously defined config values.
   - mustache function operation on config value.
   - optional parameters to override defaults.

   As an example, global configuration, common to every environment, could be defined in ```resources/app/config.edn```

```clojure
{:env "default"
 :value "common-value"
 :file "{{env}}-file.txt"}
```

   An environment specific config (eg for test) could be defined in ```env/test/resources/app/env-config.edn```.

```clojure
{:env "test"
 :other "value"}
```

   When the execution environment is setup to include "resources" and "env/test/resources" on the classpath
   (as would be done when executing tests), then calling ```(load-config "app")``` will return:

```clojure
{:env "test"
 :other "value"
 :value "common-value"
 :file "test-file.txt"}
```

   Variable evaluation is done recursively, on the final merged map until all variables have been evaluated.

   Both [[load-config]] and [[load-http-config]] accept an optional opts map, which can selectively override
   the following defaults:

```clojure
{:env-file-name "env-config.edn"
 :common-file-name "config.edn"
 :resolve-vars true}
```

  The opts arguments may also define ```:common-path``` or ```:env-path```, which would then be used
  instead of building up the path from the file name and provided path prefix.
raw docstring

load-configclj

(load-config config-path)
(load-config config-path opts)

Loads config from the classpath, using the given path prefix for env and common files.

  • config-path: path prefix for both env and common file (eg yourapp)
  • opts: optional override of default values {:env-file-name :env-path :common-file-name :common-path :resolve-vars}
  • Returns: a map which is a merge of the env and common config, optionally with all variables evualted.
Loads config from the classpath, using the given path prefix for env and common files.

- config-path:   path prefix for both env and common file (eg ```yourapp```)
- opts:          optional override of default values ```{:env-file-name :env-path :common-file-name :common-path :resolve-vars}```
- Returns:       a map which is a merge of the env and common config, optionally with all variables evualted.
sourceraw docstring

load-http-configclj/s

(load-http-config config-path)
(load-http-config config-path opts)

Loads config from server, merging the current environment config with the base application configuration.

As the server instance represents the environment, it is up to the deployment build process to ensure the appropriate config.edn and env-config.edn is deployed, typically from resources/public/<app-prefix>/config.edn and env/<environment>/resources/public/<app-prefix>/env-config.edn.

  • config-path: eg yourapp will look for /yourapp/config.edn and /yourapp/env-config.edn
  • opts: optional override of default values {:env-file-name :env-path :common-file-name :common-path :resolve-vars}
  • returns: A promesa promise that resolves to the merged config map
Loads config from server, merging the current environment config with the base application configuration.

As the server instance represents the environment, it is up to the deployment build process to ensure the appropriate config.edn and env-config.edn
is deployed, typically from ```resources/public/<app-prefix>/config.edn``` and ```env/<environment>/resources/public/<app-prefix>/env-config.edn```.

- config-path: eg ```yourapp```  will look for ```/yourapp/config.edn``` and ```/yourapp/env-config.edn```
- opts:        optional override of default values ```{:env-file-name :env-path :common-file-name :common-path :resolve-vars}```
- returns:     A promesa promise that resolves to the merged config map
sourceraw docstring

read-configclj

(read-config config-file-path)

Reads a single config file from the classpath, returning as a clojure map.

  • config-file-path: eg yourapp/config.edn
  • returns: config file as clojure map.
Reads a single config file from the classpath, returning as a clojure map.

- config-file-path:  eg ```yourapp/config.edn```
- returns: config file as clojure map.
sourceraw docstring

read-http-configclj/s

(read-http-config config-url)

Reads via http from the default server location (usually resources/public) the specified config-file at the given path.

  • config-url: eg yourapp/config.edn
  • returns: a promesa promise that resolves to the map of config values read.
Reads via http from the default server location (usually resources/public) the
specified config-file at the given path.

- config-url:  eg ```yourapp/config.edn```
- returns: a promesa promise that resolves to the map of config values read.
sourceraw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close