Skip to content

Commit

Permalink
improve property management
Browse files Browse the repository at this point in the history
  • Loading branch information
ecostanzi committed May 21, 2024
1 parent b81f58a commit 8accef2
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/main/kotlin/Configs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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"));
}
}

0 comments on commit 8accef2

Please sign in to comment.