Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
Bruce0203 committed Aug 4, 2023
1 parent 83738ba commit 74a73a7
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions server/src/main/kotlin/application/configuration/env.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package application.configuration
import io.github.cdimascio.dotenv.dotenv
import kotlin.reflect.KProperty

private val dotenv = dotenv()
private val dotenv = dotenv {
ignoreIfMissing = true
}

object EnvVar {
val serverPort by IntEnv { 8080 }
Expand All @@ -18,7 +20,7 @@ abstract class Env<T>(private val default: (() -> T)?) {
val key = property.name
return runCatching { System.getenv(key).run(::convert) }
.getOrNull()?: dotenv.get(key)?.run(::convert)
?: default?.invoke()?: throw AssertionError("$key is not exists")
?: default!!.invoke()!!
}
}

Expand Down

0 comments on commit 74a73a7

Please sign in to comment.