https://kotlinlang.org logo
Title
g

Guilherme Delgado

04/17/2021, 9:42 AM
Hi guys, I’m creating my first server that latter will be used in a KMP project. Question: how can I read values from, let’s say, a
local.properties
? This was my idea:
private fun getSecret(envKey: String, localKey: String): String = System.getenv(envKey) ?: ...(localKey,"")
Thanks!
b

Big Chungus

04/17/2021, 10:25 AM
Expect/actual into platform file apis
E.g. fs on node or File on Java
👍 1
g

Guilherme Delgado

04/17/2021, 1:12 PM
sometimes my brain freezes a bit eheh 😅
private fun getSecret(envKey: String, localKey: String): String {
    val path = "./local.properties"
    return if (File(path).exists()) {
        Properties().apply { load(FileInputStream(path)) }.getProperty(localKey, "")
    } else System.getenv(envKey) ?: ""
}