In my main namespace, I have a top level var called "settings" that initializes to empty {}.
My -main fn sets the contents of the settings using def and conj based on some command line arguments (different database hosts for production / development, etc.).
I am trying to access the contents of this map from another namespace in order to pull out some settings. When I try to compile the lane in uberjar, I get the trace "There are no such var: lb / settings".
What am I missing? Is there a more idiomatic way to handle applications like these? Is it safe to use "def" inside -main, like me, or should I use atom or ref to make it thread safe?
Thank!
(ns com.domain.main
(:use com.domain.some-other-namespace.core)
(:gen-class))
(def settings {})
(defn -main [& args]
(with-command-line-args... ;set devel? based on args
(if (true? devel?)
(def settings (conj settings {:mongodb {:host "127.0.0.1"}
:memcached {:host "127.0.0.1"}}))
(def settings (conj settings {:mongodb {:host "PRODUCTION_IP"}
:memcached {:host "PRODUCTION_IP"}})))
;file2.clj
(ns com.domain.some-other-namespace.core
(:require [main :as lb]
...)
;configure MongoDB
(congo/mongo!
:db "dbname" :host (:host (mongodb lb/settings))))
...
source
share