-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convention: Module is a separate file
- Loading branch information
Showing
10 changed files
with
92 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,8 @@ | ||
@file:JvmName("Application") | ||
package io.heapy.komok | ||
|
||
import io.heapy.komok.infra.http.server.ServerModule | ||
import io.heapy.komok.infra.uptime.JvmUptime | ||
import io.heapy.komok.tech.logging.Logger | ||
import io.heapy.komok.infra.uptime.JvmUptimeModule | ||
import io.heapy.komok.tech.di.lib.Module | ||
import io.ktor.server.cio.CIOApplicationEngine | ||
import io.ktor.server.engine.* | ||
|
||
fun main() { | ||
createApplicationModule {} | ||
createKomokApplicationModule {} | ||
.komokApplication | ||
.run() | ||
} | ||
|
||
class KomokApplication( | ||
private val server: EmbeddedServer<CIOApplicationEngine, CIOApplicationEngine.Configuration>, | ||
private val jvmUptime: JvmUptime, | ||
) { | ||
fun run() { | ||
val uptime = jvmUptime.uptime() | ||
log.info("Application started. JVM running for $uptime") | ||
server.start(wait = true) | ||
} | ||
|
||
private companion object : Logger() | ||
} | ||
|
||
@Module | ||
open class ApplicationModule( | ||
private val serverModule: ServerModule, | ||
|
||
private val jvmUptimeModule: JvmUptimeModule, | ||
) { | ||
open val komokApplication by lazy { | ||
KomokApplication( | ||
server = serverModule.server, | ||
jvmUptime = jvmUptimeModule.jvmUptime, | ||
) | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
komok-app/src/main/kotlin/io/heapy/komok/business/entrypoint/KomokApplication.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package io.heapy.komok.business.entrypoint | ||
|
||
import io.heapy.komok.infra.uptime.JvmUptime | ||
import io.heapy.komok.tech.logging.Logger | ||
import io.ktor.server.cio.CIOApplicationEngine | ||
import io.ktor.server.engine.EmbeddedServer | ||
|
||
class KomokApplication( | ||
private val server: EmbeddedServer<CIOApplicationEngine, CIOApplicationEngine.Configuration>, | ||
private val jvmUptime: JvmUptime, | ||
) { | ||
fun run() { | ||
val uptime = jvmUptime.uptime() | ||
log.info("Application started. JVM running for $uptime") | ||
server.start(wait = true) | ||
} | ||
|
||
private companion object : Logger() | ||
} |
18 changes: 18 additions & 0 deletions
18
komok-app/src/main/kotlin/io/heapy/komok/business/entrypoint/KomokApplicationModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package io.heapy.komok.business.entrypoint | ||
|
||
import io.heapy.komok.infra.http.server.ServerModule | ||
import io.heapy.komok.infra.uptime.JvmUptimeModule | ||
import io.heapy.komok.tech.di.lib.Module | ||
|
||
@Module | ||
open class KomokApplicationModule( | ||
private val serverModule: ServerModule, | ||
private val jvmUptimeModule: JvmUptimeModule, | ||
) { | ||
open val komokApplication by lazy { | ||
KomokApplication( | ||
server = serverModule.server, | ||
jvmUptime = jvmUptimeModule.jvmUptime, | ||
) | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
komok-app/src/main/kotlin/io/heapy/komok/business/login/LoginRoute.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../src/main/kotlin/io/heapy/komok/infra/http/server/ServerApplicationConfigurationModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
komok-app/src/main/kotlin/io/heapy/komok/infra/jwt/JwtModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package io.heapy.komok.infra.jwt | ||
|
||
import io.heapy.komok.business.login.JwtConfiguration | ||
import io.heapy.komok.infra.time.TimeSourceModule | ||
import io.heapy.komok.tech.config.ConfigurationModule | ||
import io.heapy.komok.tech.di.lib.Module | ||
|
||
@Module | ||
open class JwtModule( | ||
private val configurationModule: ConfigurationModule, | ||
private val timeSourceModule: TimeSourceModule, | ||
) { | ||
open val jwtConfiguration: JwtConfiguration by lazy { | ||
configurationModule | ||
.config | ||
.read( | ||
deserializer = JwtConfiguration.serializer(), | ||
path = "jwt", | ||
) | ||
.also { config -> | ||
require(config.secret.length >= 128) { | ||
"Secret must be at least 128 characters long" | ||
} | ||
} | ||
} | ||
|
||
open val jwtService: JwtService by lazy { | ||
DefaultJwtService( | ||
jwtConfiguration = jwtConfiguration, | ||
timeSource = timeSourceModule.timeSource, | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
komok-app/src/main/kotlin/io/heapy/komok/infra/uptime/JvmUptimeModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package io.heapy.komok.infra.uptime | ||
|
||
import io.heapy.komok.tech.di.lib.Module | ||
|
||
@Module | ||
open class JvmUptimeModule { | ||
open val jvmUptime: JvmUptime by lazy { | ||
DefaultJvmUptime() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters