Skip to content

Instantly share code, notes, and snippets.

@dirtyvagabond
Created February 8, 2012 19:23
Show Gist options
  • Save dirtyvagabond/1772506 to your computer and use it in GitHub Desktop.
Save dirtyvagabond/1772506 to your computer and use it in GitHub Desktop.
(ns datastore-api-server.conf
"Configuration utility."
(:use [clojure.tools.logging :only (info debug error)])
(:use [fs.core :only (exists?)]))
(def DEFAULT-CONF-FILES ["server-conf.clj" "resources/server-conf.clj"])
(defn load-when
"If path exists, returns the data structure represented in the
file at path. Otherwise returns nil."
[path]
(if (exists? path)
(do
(info "conf.load-when: loading conf from" path)
(read-string (slurp path)))
(info "conf.load-when: no file at" path "; skipping")))
(defn default-conf
[]
(apply merge (map load-when DEFAULT-CONF-FILES)))
(def ^:dynamic *conf* (default-conf))
(defn add-file!
"Merges the configuration in path into current *conf*. In the case of
identical keys, the configuration in path will take precedence."
[path]
(def *conf* (merge *conf* (load-when path))))
; This is the primary function the application is expected to use to
; obtain final configuration data.
(defn conf [] *conf*)
(defn show
"Convenience fn to print conf to stdout"
[]
(info "conf.show: conf:" (conf)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment