Skip to content

Instantly share code, notes, and snippets.

@eneroth
Last active October 1, 2015 19:20
Show Gist options
  • Save eneroth/f52dab6943a17e2e56e0 to your computer and use it in GitHub Desktop.
Save eneroth/f52dab6943a17e2e56e0 to your computer and use it in GitHub Desktop.
;; Load config
(defn load-config [config-path]
(let [ch (chan)]
(go
(let [{:keys [succeeded data]} (<! (path/resolve config-path))
abs-path data]
(if-not succeeded
(failure ch data (str "load-config: couldn't resolve path '" config-path "'"))
(let [{:keys [succeeded data]} (<! (file/read abs-path :utf-8))
config-content data]
(if-not succeeded
(failure ch data (str "load-config: could not read the config from location '" config-path "'"))
(let [{:keys [succeeded data]} (<! (edn/parse config-content))]
(if-not succeeded
(failure ch data (str "load-config: couldn't parse config content.") config-content)
(success ch data))))))))
ch))
;; Load config
(defn load-config [config-path]
(let [ch (chan)]
(go-work ch
[abs-path (path/resolve config-path) (str "load-config: couldn't resolve path '" config-path "'")
config-content (file/read abs-path :utf-8) (str "load-config: could not read the config from location '" config-path "'")
edn (edn/parse config-content) "load-config: couldn't parse config content."]
(success ch data))
ch))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment