Skip to content

Instantly share code, notes, and snippets.

@bbbates
Last active January 1, 2016 15:59
Show Gist options
  • Save bbbates/8167593 to your computer and use it in GitHub Desktop.
Save bbbates/8167593 to your computer and use it in GitHub Desktop.
Merging simple map-based environment configuration
(def base-config
{
:value "some value"
})
(defn- merge-cfg-item
[base-item override-item]
(cond
(and (every? map? [base-item override-item]) (not (contains? override-item :replace-all!)))
(merge-with merge-cfg-item base-item override-item)
(and (every? map? [base-item override-item]) (contains? override-item :replace-all!))
(dissoc override-item :replace-all!)
:else override-item))
(defn merge-cfg
[base-cfg override-cfg]
(merge-with merge-cfg-item base-cfg override-cfg))
(def ^{:private true} region-config
(if-let [region (System/getProperty "region")]
(merge-cfg base-config
(read-string (slurp (io/input-stream (io/resource (apply str "conf/" region))))))
base-config))
(defn get-cfg
[& kws]
(get-in region-config ks))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment