https://kotlinlang.org logo
#ktor
Title
# ktor
e

Eduard Boloș

08/12/2018, 9:47 PM
another question: is it possible to use Config4k (https://github.com/config4k/config4k) with ktor? I didn’t find any way to access the underlying
com.typesafe.config.Config
object, am I missing something?
r

robin

08/13/2018, 6:59 PM
I ran into that, too, wanted to use some advanced Config features and was frustrated to find that we can't access it directly. This is what I ended up doing:
Copy code
fun ApplicationConfig.getHoconConfig(): Config {
    require(this is HoconApplicationConfig)
    val internalConfigField = HoconApplicationConfig::class.java.getDeclaredField("config")
    internalConfigField.isAccessible = true
    return internalConfigField.get(this) as Config
}
I just call that function when starting the server to retrieve the actual config, works fine so far.
e

Eduard Boloș

08/13/2018, 8:26 PM
yeah, I was thinking about using reflection as well. I wanted to just recreate the
Config
object similar to how it’s done in
CommandLine.kt
, but again, I have a hard time accessing the arguments the application was started with 😐
9 Views