A Clojure library for reading a single EDN configuration file available in your resources. It wraps aero and provides some convenience functions.
Add to your project's dependencies:
Note that previous versions used a [turbovote/resource-config] dependency! This must be changed when updating to 1.0.0.
config.edn file in your classpath.; config.edn
{:server {:hostname "localhost"
          :port 8080}
 :startup-message "Hello, world!"
 :auth-token #env "AUTH_TOKEN"}
; core.clj
(ns my-app.core
  (:require [resource-config.core :refer [config]]))
;; this will throw an exception if the value is not in the config
(defn running-locally? []
  (= "localhost" (config [:server :hostname])))
;; you can set a default value like this (never throws exception)
(defn get-database-url []
  (config [:database :url] "postgres://default-db"))
(ns my-app.core
  (:require [mount.core :refer [defstate] :as mount]
            [resource-config.core :as rc]))
  
(defstate config
  :start rc/config
  :stop (rc/reload-config!))
  
(mount/start)
(config [:database :url] "postgres://default-db")
The following data readers are provided:
#resource-config/edn: The value is read from an edn string.There is a lein plugin that sets environment vars. This allows them to be checked into the repo. It needs to be invoked, so run the tests like this:
lein with-env-vars test
Copyright © 2015-2020 Democracy Works, Inc.
Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.
Can you improve this documentation? These fine people already did:
Wes Morgan, Chris Shea, cthompson, Egg Syntax, Dave Della Costa, Eric Normand, Christopher Shea & nherzingEdit on GitHub
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs | 
| ← | Move to previous article | 
| → | Move to next article | 
| Ctrl+/ | Jump to the search field |