complete startup module

This commit is contained in:
2022-12-05 22:31:15 +06:00
parent 2a4570eafc
commit b17931e7bd
6 changed files with 80 additions and 52 deletions

View File

@@ -2,31 +2,35 @@ 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 dev.inmo.micro_utils.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.serialization.json.jsonObject
import org.koin.core.KoinApplication
import org.koin.core.context.GlobalContext
import org.koin.dsl.module
import java.io.File
package dev.inmo.micro_utils.startup.launcher
import dev.inmo.
class ServerLauncher : ServerPlugin {
val defaultJson = Json {
ignoreUnknownKeys = true
}
suspend fun main(args: Array<String>) {
KSLog.default = KSLog("PlaguBot")
KSLog.default = KSLog("ServerLauncher")
val (configPath) = args
val file = File(configPath)
KSLog.i("Start read config from ${file.absolutePath}")
val json = defaultJson.parseToJsonElement(file.readText()).jsonObject
KSLog.i("Config has been read")
ServerLauncher.start().join()
with(StartupLauncher) {
logger.i("Start initialization")
val koinApp = KoinApplication.init()
koinApp.modules(
module {
setupDI(json)
}
)
logger.i("Modules loaded")
GlobalContext.startKoin(koinApp)
logger.i("Koin started")
startPlugin(koinApp.koin)
logger.i("Behaviour builder has been setup")
}
}