mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2024-12-18 14:47:15 +00:00
ktor server createKtorServer extensions
This commit is contained in:
parent
afca09cc1d
commit
31fdcf74a5
@ -2,6 +2,10 @@
|
|||||||
|
|
||||||
## 0.8.4
|
## 0.8.4
|
||||||
|
|
||||||
|
* `Ktor`:
|
||||||
|
* `Server`:
|
||||||
|
* Several new `createKtorServer`
|
||||||
|
|
||||||
## 0.8.3
|
## 0.8.3
|
||||||
|
|
||||||
* `Common`:
|
* `Common`:
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package dev.inmo.micro_utils.ktor.server
|
package dev.inmo.micro_utils.ktor.server
|
||||||
|
|
||||||
|
import dev.inmo.micro_utils.ktor.server.configurators.KtorApplicationConfigurator
|
||||||
import io.ktor.application.Application
|
import io.ktor.application.Application
|
||||||
import io.ktor.server.cio.CIO
|
import io.ktor.server.cio.CIO
|
||||||
import io.ktor.server.engine.*
|
import io.ktor.server.engine.*
|
||||||
@ -31,3 +32,27 @@ fun createKtorServer(
|
|||||||
port: Int = Random.nextInt(1024, 65535),
|
port: Int = Random.nextInt(1024, 65535),
|
||||||
block: Application.() -> Unit
|
block: Application.() -> Unit
|
||||||
): ApplicationEngine = createKtorServer(CIO, host, port, block)
|
): ApplicationEngine = createKtorServer(CIO, host, port, block)
|
||||||
|
|
||||||
|
fun <TEngine : ApplicationEngine, TConfiguration : ApplicationEngine.Configuration> createKtorServer(
|
||||||
|
engine: ApplicationEngineFactory<TEngine, TConfiguration>,
|
||||||
|
host: String = "localhost",
|
||||||
|
port: Int = Random.nextInt(1024, 65535),
|
||||||
|
configurators: List<KtorApplicationConfigurator>
|
||||||
|
): TEngine = createKtorServer(
|
||||||
|
engine,
|
||||||
|
host,
|
||||||
|
port
|
||||||
|
) {
|
||||||
|
configurators.forEach { it.apply { configure() } }
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create server with [CIO] server engine without starting of it
|
||||||
|
*
|
||||||
|
* @see ApplicationEngine.start
|
||||||
|
*/
|
||||||
|
fun createKtorServer(
|
||||||
|
host: String = "localhost",
|
||||||
|
port: Int = Random.nextInt(1024, 65535),
|
||||||
|
configurators: List<KtorApplicationConfigurator>
|
||||||
|
): ApplicationEngine = createKtorServer(CIO, host, port, configurators)
|
||||||
|
Loading…
Reference in New Issue
Block a user