asad.awadia
03/21/2019, 12:37 AMcreateHttpServer {
options = myServerOptionsObjectVariableFromAboveSomewhere
port = 8080
}
which should run effectively vertx().createHttpServer(options).listen(port)
?Shawn
03/21/2019, 12:39 AMShawn
03/21/2019, 12:39 AMClassWithOptionsAndPortProperties.() -> Unit
Shawn
03/21/2019, 12:40 AMasad.awadia
03/21/2019, 12:40 AMasad.awadia
03/21/2019, 12:41 AMfun httpServer(f: Vertx.() -> Unit) {
Vertx.vertx().createHttpServer(options).listen(port)
}
asad.awadia
03/21/2019, 12:41 AMShawn
03/21/2019, 12:43 AMVertx
object, then you’ll have to write some kind of adapter or builder to translate the parameters you want to accept to the according ones on your end result typeShawn
03/21/2019, 12:45 AMVertx.vertx().apply(f)
where f
is your config functionShawn
03/21/2019, 12:47 AMVertexConfig
class you can useShawn
03/21/2019, 1:51 AMclass VertxConfig {
var port: Short = 0
lateinit var options: VertxOptions
}
fun createHttpServer(block: VertxConfig.() -> Unit): Vertx {
val config = VertxConfig().apply(block)
return Vertx.vertx()
.createHttpServer(config.options)
.listen(config.port)
}
// usage
createHttpServer {
port = 8080
options = serverOptions
}
asad.awadia
03/21/2019, 1:57 AMasad.awadia
03/21/2019, 1:57 AMasad.awadia
03/21/2019, 1:57 AM