A simple environment configuration library for Clojure.
Add the following dependency to your project.clj
file:
-
Add a base config file.
Create a new file at
/resources/conf/base.edn
. This will be the base configuration that's loaded every time your app runs. For example:{:foo "bar" :port 5000}
-
(Optional) Add environment-specific config files.
If desired, you can set additional environment-specific config files for your app. Add additional files at
/resources/conf/${ENV}.edn
where $ENV is any string of your choosing. For example, following on the example above, if in production you'd like your app to run on port 80, you might create/resources/conf/prod.edn
to look like this:{:port 80}
-
(Optional) Add late binding variables.
Configuration variables can refer to other configuration variables using the
#var
syntax:{ :database-url "sql://fake:1234/devdb" :bt-database-url #var :database-url }
-
Add code in your app to use your config values.
For example:
(require '[conf.core :as conf]) (def foo (conf/get :foo)) (defn -main [& args] (println "foo is" foo) (start-server {:port (conf/get :port)}))
-
Run your app.
To use just the base config, run your app normally, e.g.
lein run
. If you'd like to enable an environment-specific config, be sure to pass theCONF_ENV
environment variable, e.g.CONF_ENV=prod lein run
.
Copyright © 2014-present Jim Brusstar, Standard Treasury
Distributed under the terms of the MIT License.