integrant

2018-05-01T16:27:22.000443Z

what's the recommended way to provide alternate implementations for keys (e.g. for dev mode)?

2018-05-01T16:27:28.000337Z

careful ns loading?

2018-05-03T22:22:04.000456Z

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.

2018-05-01T16:29:46.000016Z

a completely different config and rename-keys after ig/init?

2018-05-01T16:30:18.000662Z

that's gotta be it

2018-05-01T16:32:53.000730Z

@potetm Why do you need the rename-keys?

2018-05-01T16:39:33.000344Z

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.

2018-05-01T16:40:01.000050Z

@curlyfry

2018-05-01T16:41:01.000666Z

Right, but why rename the keys if you supply a different config?

2018-05-01T16:41:33.000166Z

so that the app doesn't have to know that you're providing an alternate impl

2018-05-01T16:44:11.000549Z

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!

2018-05-01T16:45:08.000142Z

(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)))

2018-05-01T16:45:20.000750Z

how do you provide different impls?

2018-05-01T16:45:58.000480Z

for a single key

2018-05-01T16:46:33.000495Z

each key would have to "know" about the different possible impls, I think

2018-05-01T16:46:50.000175Z

unless you have different keys 😕

2018-05-01T16:48:47.000335Z

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)}}

2018-05-01T16:49:27.000730Z

I just use two separate maps: (if dev-mode? dev-config prod-config)

2018-05-01T16:50:43.000623Z

Like your example there!

2018-05-01T16:50:53.000177Z

the last example?

2018-05-01T16:50:58.000489Z

Yes

2018-05-01T16:51:01.000397Z

ah okay

2018-05-01T16:51:10.000023Z

yeah that works 🙂

2018-05-01T16:51:15.000351Z

you finally got me there 🙂

👍 1
2018-05-01T16:52:42.000436Z

I think I also tend to use merge to add to/override the base config with dev stuff

2018-05-01T16:54:04.000344Z

right, makes sense

2018-05-01T16:57:17.000733Z

i use https://github.com/juxt/aero for reading my integrant config, it supports a #profile tag for exactly this use case