最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

kotlin - Using configure script with Ktor 3 CoroutineScope.embeddedServer extension function - Stack Overflow

programmeradmin4浏览0评论

I am using Ktor 3.x and am looking to start an embedded server using the Coroutine scope extension function, while also supplying my own configure script.

The documentation I am referencing is here.

As we can see from the function signature, there exists one which allows you to pass your own configure: TConfiguration.() -> Unit = {}.

fun <TEngine : ApplicationEngine, TConfiguration : ApplicationEngine.Configuration> embeddedServer(
    factory: ApplicationEngineFactory<TEngine, TConfiguration>, 
    environment: ApplicationEnvironment = applicationEnvironment(), 
    configure: TConfiguration.() -> Unit = {}, 
    module: Application.() -> Unit = {}
): EmbeddedServer<TEngine, TConfiguration>

Observing the extension functions from CoroutineScope, they do not allow us to pass a configure block:

fun <TEngine : ApplicationEngine, TConfiguration : ApplicationEngine.Configuration> CoroutineScope.embeddedServer(
    factory: ApplicationEngineFactory<TEngine, TConfiguration>, 
    vararg connectors: EngineConnectorConfig = arrayOf(), 
    watchPaths: List<String> = listOf(WORKING_DIRECTORY_PATH), 
    parentCoroutineContext: CoroutineContext = EmptyCoroutineContext, 
    module: Application.() -> Unit
): EmbeddedServer<TEngine, TConfiguration>

&

fun <TEngine : ApplicationEngine, TConfiguration : ApplicationEngine.Configuration> CoroutineScope.embeddedServer(
    factory: ApplicationEngineFactory<TEngine, TConfiguration>, 
    port: Int = 80, 
    host: String = "0.0.0.0", 
    watchPaths: List<String> = listOf(WORKING_DIRECTORY_PATH), 
    parentCoroutineContext: CoroutineContext = EmptyCoroutineContext, 
    module: Application.() -> Unit
): EmbeddedServer<TEngine, TConfiguration>

What is the expected way to gain the configure functionality when working with the extension function?

发布评论

评论列表(0)

  1. 暂无评论