I'm toying with using integrant and would like some advice. I am using config data generated by a function so that I can programatically set defaults and use some fns to generate some data I'm injecting to the different init-keys. I am aware I can replace a lot of this by just doing an edn and creating more init-keys or prep-keys to further condition that edn data for the actual runtime code. is there any benefit to doing this. here is my config.clj https://github.com/dantheobserver/parrot-api/blob/implement.memory.store/src/clj/dantheobserver/parrot_api/config.clj
I think your way is good. I personally use aero to read the configuration from a file and handle different run profiles (dev/test/staging/production) all of which have their own defaults and override possibilities.
I did look at some other files and noticed that you can include function calls. I didn't understand why he used the hash symbol in front of the function them saw that it was a way to store function calls in edn. That makes it a lot easier to move to a file since some of my config relies on env vars.
Thanks for responding btw
(defmethod aero.core/reader 'envr
[_ _ s]
(env s))
(defmethod aero.core/reader 'component
[opts tag value]
(integrant/ref value))
I use the above readers with aero to read the config with environment variables.
I was wondering, if I'm referencing integrant.core :as ig why does aero not look for that when it attempts to read it.
if I have #ig/ref in my config
I guess I have to do something like
(binding [*data-readers* {'ig/ref ig/ref}]
(aero/read-config (<http://clojure.java.io/resource|clojure.java.io/resource> "config.edn")))
You can just defmethod the reader, take my snippet above and replace component with ig/ref. Aero has its own multimethod for adding readers.
Cool I think I got a good solution using aero, consolidates things nicely, just took some time experimenting
@theeternalpulse @sandqvist thanks for the "secret sauce" I stumbled upon the same problem with environment variables. I'll use Aero too 🙂
It is almost better than christmas morning
@jarvinenemil I should push my branch with the aero changes, it requires some divergences with integrant, but I like the ability to add edn tag readers easily. My config.clj now is just the readers for some edn tags and a facade to read the config, but the config itself is in edn
@theeternalpulse It would be awesome to see your aero changes, thanks for sharing your work!
also, one thing I don't get, is that in the talk I watched about it, it says that integrant loads the namespaces of the various keys so you don't have to require them. I'm not sure you had to do that for namespaced keywords. Also if a reference a keyword as my.namespace/some-key
in my.namespace
can I just do (ig/init-key ::some-key
for short?
That is how i do it.
as I do here: https://github.com/dantheobserver/parrot-api/blob/implement.memory.store/src/clj/dantheobserver/parrot_api/store.clj#L22