Any way to add constant key in `edn`?
lkyhfx opened this issue · comments
Read through the documentation, can't find a way to add a constant key to config.edn
like:
{:port 8080
:adapter/jetty {:port #ig/ref :port, :handler #ig/ref :handler/greet}
:handler/greet {:name "Alice"}}
which :adapter/jetty
refer to :port 8080
.
Yes, you can define a key as a constant just by returning itself on initiation:
(defmethod ig/init-key :const/port [_ v] v)
You could also define a parent key:
(defmethod ig/init-key :const/value [_ v] v)
And then in your configuration, use the vector syntax:
{[:const/value :server/port] 8080
:adapter/jetty {:port #ig/ref :server/port, :handler #ig/ref :handler/greet}}
There's also configuration reading tools like Aero that will allow constants to be inserted in.
Or you could pre-process the configuration. It's just a map, after all, so you could insert your own code to handle constants.
I realize that there's no single "Integrant way" to do this. To be honest, I'm unsure the best way to solve this idiomatically in Integrant, or if it's even an Integrant problem.
Thanks! Your suggestions have been very helpful, and I'll explore the options you've mentioned.