what's the recommended way to provide alternate implementations for keys (e.g. for dev mode)?
careful ns loading?
Just to mention that duct has a thin layer ontop of integrant that supports this sort of thing through :duct/include
Basically you have multiple integrant maps in separate edn files that get meta-merged together in order. e.g. you can do something like:
;; dev.edn
{:duct/include ["main.edn"]
:service.dev/monitoring {:dev :version}
}
;; main.edn
{
:service.prod/monitoring {:prod :version}
:the/service {:monitoring #ig/ref :service/monitoring}
}
(assuming both dev/prod versions derive from the :service/monitoring)
Or you can easily wire something like this up yourself.a completely different config and rename-keys
after ig/init
?
that's gotta be it
@potetm Why do you need the rename-keys
?
the app would expect certain keys to exist. e.g. :service/monitoring
. In prod I want to hit a monitoring service, in dev I just want to log those calls to a file.
Right, but why rename the keys if you supply a different config?
so that the app doesn't have to know that you're providing an alternate impl
Sorry, still not getting it :) I just use a different map with the same set of keys (but different impls) for dev/prod. Sounds like you have something that works though!
(defn my-app [{:keys [:service/monitoring] :as conf}]
(monitor-things monitoring ...))
(defn dev [& _]
(let [sys (ig/init {:service/monitoring-dev-mode {}})]
(my-app (set/rename-keys sys {:service/monitoring-dev-mode :service/monitoring}))))
(defn -main [& _]
(let [sys (ig/init {:service/monitoring {:uri "foo"}})]
(my-app sys)))
how do you provide different impls?
for a single key
each key would have to "know" about the different possible impls, I think
unless you have different keys 😕
I suppose you can use another layer of indirection. So
{:service/monitoring-dev-mode {}
:service/monitoring {:impl (ig/ref :service/monitoring-dev-mode)}}
{:service/monitoring-prod-mode {}
:service/monitoring {:impl (ig/ref :service/monitoring-prod-mode)}}
I just use two separate maps: (if dev-mode? dev-config prod-config)
Like your example there!
the last example?
Yes
ah okay
yeah that works 🙂
you finally got me there 🙂
I think I also tend to use merge
to add to/override the base config with dev stuff
right, makes sense
i use https://github.com/juxt/aero for reading my integrant config, it supports a #profile
tag for exactly this use case