mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2025-09-09 02:00:01 +00:00
initialize startup module
This commit is contained in:
17
startup/launcher/build.gradle
Normal file
17
startup/launcher/build.gradle
Normal file
@@ -0,0 +1,17 @@
|
||||
plugins {
|
||||
id "org.jetbrains.kotlin.multiplatform"
|
||||
id "org.jetbrains.kotlin.plugin.serialization"
|
||||
}
|
||||
|
||||
apply from: "$mppJavaProjectPresetPath"
|
||||
|
||||
kotlin {
|
||||
sourceSets {
|
||||
commonMain {
|
||||
dependencies {
|
||||
api internalProject("micro_utils.startup.plugin")
|
||||
api libs.kslog
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
9
startup/launcher/src/commonMain/kotlin/Config.kt
Normal file
9
startup/launcher/src/commonMain/kotlin/Config.kt
Normal file
@@ -0,0 +1,9 @@
|
||||
package dev.inmo.micro_utils.startup.launcher
|
||||
|
||||
import dev.inmo.micro_utils.startup.plugin.ServerPlugin
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class Config(
|
||||
val plugins: List<ServerPlugin>
|
||||
)
|
38
startup/launcher/src/commonMain/kotlin/ServerLauncher.kt
Normal file
38
startup/launcher/src/commonMain/kotlin/ServerLauncher.kt
Normal file
@@ -0,0 +1,38 @@
|
||||
package dev.inmo.micro_utils.startup.launcher
|
||||
|
||||
import dev.inmo.micro_utils.startup.plugin.ServerPlugin
|
||||
import kotlinx.serialization.json.Json
|
||||
import kotlinx.serialization.json.JsonObject
|
||||
import org.koin.core.Koin
|
||||
import org.koin.core.module.Module
|
||||
import org.koin.dsl.module
|
||||
|
||||
class ServerLauncher : ServerPlugin {
|
||||
val defaultJson = Json {
|
||||
ignoreUnknownKeys = true
|
||||
}
|
||||
|
||||
override fun Module.setupDI(config: JsonObject) {
|
||||
val pluginsConfig = defaultJson.decodeFromJsonElement(Config.serializer(), config)
|
||||
|
||||
single { pluginsConfig }
|
||||
|
||||
includes(
|
||||
pluginsConfig.plugins.map {
|
||||
module {
|
||||
with(it) {
|
||||
setupDI(config)
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
override suspend fun Koin.startPlugin() {
|
||||
get<Config>().plugins.forEach {
|
||||
with(it) {
|
||||
startPlugin()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
24
startup/launcher/src/jvmMain/kotlin/ServerLauncher.kt
Normal file
24
startup/launcher/src/jvmMain/kotlin/ServerLauncher.kt
Normal file
@@ -0,0 +1,24 @@
|
||||
package dev.inmo.micro_utils.startup.launcher
|
||||
|
||||
import dev.inmo.kslog.common.KSLog
|
||||
import dev.inmo.kslog.common.i
|
||||
import dev.inmo.micro_utils.startup.plugin.ServerPlugin
|
||||
import kotlinx.serialization.json.Json
|
||||
import kotlinx.serialization.json.JsonObject
|
||||
import org.koin.core.Koin
|
||||
import org.koin.core.module.Module
|
||||
import org.koin.dsl.module
|
||||
import java.io.File
|
||||
|
||||
suspend fun main(args: Array<String>) {
|
||||
|
||||
KSLog.default = KSLog("PlaguBot")
|
||||
val (configPath) = args
|
||||
val file = File(configPath)
|
||||
KSLog.i("Start read config from ${file.absolutePath}")
|
||||
val json = defaultJsonFormat.parseToJsonElement(file.readText()).jsonObject
|
||||
val config = defaultJsonFormat.decodeFromJsonElement(Config.serializer(), json)
|
||||
KSLog.i("Config has been read")
|
||||
|
||||
PlaguBot(json, config).start().join()
|
||||
}
|
Reference in New Issue
Block a user