https://kotlinlang.org logo
#http4k
Title
# http4k
j

joscha.alisch

10/12/2019, 8:08 AM
Hey folks 🙂 What would be your recommended way of creating an environment config from multiple `EnvironmentKey`s ? Say I want to create an instance of
data class MongoDBSettings(val host: String, val port: Int)
from the environment variables
MONGO_HOST
and
MONGO_PORT
. Would I have them as separate `EnvironmentKey`s and do the mapping outside or is there some lens magic where I can do something like
EnvironmentKey.mongoSettings().required("MONGO_HOST", "MONGO_PORT")
?
s

s4nchez

10/12/2019, 8:31 AM
@joscha.alisch right now the only option is individual keys. They can be composed to build your settings object inside any normal function (standalone, extension, or companion). My personal preference is to have extensions to Environment to do this extraction of more complex structures.
2 Views