From 8accef243436313d4027af6e87508f3fd7e942f7 Mon Sep 17 00:00:00 2001 From: Enrico Costanzi Date: Tue, 21 May 2024 12:47:00 +0200 Subject: [PATCH] improve property management --- src/main/kotlin/Configs.kt | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/Configs.kt b/src/main/kotlin/Configs.kt index b51f68a..f6145da 100644 --- a/src/main/kotlin/Configs.kt +++ b/src/main/kotlin/Configs.kt @@ -11,7 +11,6 @@ class Configs { loadPropertyFile("classpath:application.properties"), // default dev properties loadPropertyFile("classpath:application-local.properties"), // default personal properties (not versioned) loadPropertyFile("application.properties"), // file system properties (in production) - buildPropertiesFromEnv("PORT", "CUSTOM_MESSAGE") // environment variables always win ) fun loadPropertyFile(filePath: String): Properties { @@ -57,11 +56,14 @@ class Configs { return propsFromEnv; } - fun getProperty(propertyName: String): String { - return properties.getProperty(propertyName, "NONE"); + fun getProperty(propertyName: String, default: String = "NONE") : String { + return when(val value = System.getenv(propertyName)) { + null -> properties.getProperty(propertyName, default) + else -> value; + } } fun getIntegerProperty(propertyName: String): Int { - return Integer.parseInt(properties.getProperty(propertyName, "8080")); + return Integer.parseInt(getProperty(propertyName, "8080")); } }