Skip to content

Commit

Permalink
Use braceless syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
adamw committed Sep 23, 2024
1 parent 7cd0cb3 commit 32702c4
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 34 deletions.
3 changes: 1 addition & 2 deletions backend/src/main/twirl/MainFutureNettyScala3.scala.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ import ExecutionContext.Implicits.global
val program =
for
binding <- NettyFutureServer(@if(addMetrics) {serverOptions}).port(port).addEndpoints(Endpoints.all).start()
_ <- Future {
_ <- Future:
println(s"@if(addDocumentation){Go to http://localhost:${binding.port}/docs to open SwaggerUI. }else{Server started at http://localhost:${binding.port}. }Press ENTER key to exit.")
StdIn.readLine()
}
stop <- binding.stop()
yield stop

Expand Down
3 changes: 1 addition & 2 deletions backend/src/main/twirl/MainFuturePekkoScala3.scala.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@ import scala.io.StdIn
val bindingFuture = Http()
.newServerAt("localhost", port)
.bindFlow(route)
.map { binding =>
.map: binding =>
println(s"@if(addDocumentation){Go to http://localhost:${binding.localAddress.getPort}/docs to open SwaggerUI.}else{Server started at http://localhost:${binding.localAddress.getPort}.} Press ENTER key to exit.")
binding
}

StdIn.readLine()

Expand Down
10 changes: 4 additions & 6 deletions backend/src/main/twirl/MainFutureVertxScala3.scala.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,17 @@ import scala.io.StdIn
val router = Router.router(vertx)

Endpoints.all
.foreach(endpoint => {
.foreach: endpoint =>
VertxFutureServerInterpreter(@if(addMetrics) {serverOptions}).route(endpoint)
.apply(router)
})

val program = for {
val program = for
binding <- server.requestHandler(router).listen(port).asScala
_ <- Future {
_ <- Future:
println(s"@if(addDocumentation){Go to http://localhost:${binding.actualPort()}/docs to open SwaggerUI. }else{Server started at http://localhost:${binding.actualPort()}. }Press ENTER key to exit.")
StdIn.readLine()
}
stop <- binding.close().asScala
} yield stop
yield stop

Await.result(program, Duration.Inf)

7 changes: 3 additions & 4 deletions backend/src/main/twirl/MainIOHttp4sScala3.scala.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,9 @@ object Main extends IOApp:
.withPort(port)
.withHttpApp(Router("/" -> routes).orNotFound)
.build
.use { server =>
for {
.use: server =>
for
_ <- IO.println(s"@if(addDocumentation){Go to http://localhost:${server.address.getPort}/docs to open SwaggerUI. }else{Server started at http://localhost:${server.address.getPort}. }Press ENTER key to exit.")
_ <- IO.readLine
} yield ()
}
yield ()
.as(ExitCode.Success)
3 changes: 1 addition & 2 deletions backend/src/main/twirl/MainIONettyScala3.scala.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ object Main extends IOApp:
NettyCatsServer
.io()
}
.use { server =>
.use: server =>
for
bind <- server
.port(port)
Expand All @@ -30,5 +30,4 @@ object Main extends IOApp:
_ <- IO.readLine
_ <- bind.stop()
yield bind
}
.as(ExitCode.Success)
13 changes: 5 additions & 8 deletions backend/src/main/twirl/MainIOVertxScala3.scala.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,24 @@ object Main extends IOApp:

Dispatcher[IO]
@if(addMetrics) {
.map(d => {
.map: d =>
VertxCatsServerOptions
.customiseInterceptors(d)
.metricsInterceptor(Endpoints.prometheusMetrics.metricsInterceptor())
.options
})
}
.use { @if(addMetrics) {serverOptions} else {dispatcher} =>
for {
.use: @if(addMetrics) {serverOptions} else {dispatcher} =>
for
bind <- IO.delay {
Endpoints.all
.foreach(endpoint => {
.foreach: endpoint =>
VertxCatsServerInterpreter[IO](@if(addMetrics) {serverOptions} else {dispatcher})
.route(endpoint)
.apply(router)
})
server.requestHandler(router).listen(port)
}.flatMap(_.asF[IO])
_ <- IO.println(s"@if(addDocumentation){Go to http://localhost:${bind.actualPort()}/docs to open SwaggerUI. }else{Server started at http://localhost:${bind.actualPort()}. }Press ENTER key to exit.")
_ <- IO.readLine
_ <- IO.delay(server.close).flatMap(_.asF[IO].void)
} yield bind
}
yield bind
.as(ExitCode.Success)
7 changes: 3 additions & 4 deletions backend/src/main/twirl/MainZIOHttp4sScala3.scala.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@ object Main extends ZIOAppDefault:
.withPort(port)
.withHttpApp(Router("/" -> routes).orNotFound)
.build
.use { server =>
for {
.use: server =>
for
_ <- Console.printLine(s"@if(addDocumentation){Go to http://localhost:${server.address.getPort}/docs to open SwaggerUI. }else{Server started at http://localhost:${server.address.getPort}. }Press ENTER key to exit.")
_ <- Console.readLine
} yield ()
}
yield ()
7 changes: 3 additions & 4 deletions backend/src/main/twirl/MainZIOVertxScala3.scala.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ object Main extends ZIOAppDefault:
val server = vertx.createHttpServer()
val router = Router.router(vertx)

(for {
(for
serverStart <- ZIO
.attempt {
@if(addMetrics) {
Expand All @@ -28,14 +28,13 @@ object Main extends ZIOAppDefault:
.options
}
Endpoints.all
.foreach(endpoint => {
.foreach: endpoint =>
VertxZioServerInterpreter(@if(addMetrics) {serverOptions})
.route(endpoint)
.apply(router)
})
server.requestHandler(router).listen(port)
}.flatMap(_.asRIO)
_ <- Console.printLine(s"@if(addDocumentation){Go to http://localhost:${serverStart.actualPort()}/docs to open SwaggerUI. }else{Server started at http://localhost:${serverStart.actualPort()}. }Press ENTER key to exit.")
_ <- Console.readLine
} yield serverStart)
yield serverStart)
.exitCode
4 changes: 2 additions & 2 deletions backend/src/main/twirl/MainZIOhttpZIOScala3.scala.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ object Main extends ZIOAppDefault:

val port = sys.env.get("HTTP_PORT").flatMap(_.toIntOption).getOrElse(8080)

(for {
(for
actualPort <- Server.install(app) // or .serve if you don't need the port and want to keep it running without manual readLine
_ <- Console.printLine(s"@if(addDocumentation){Go to http://localhost:${actualPort}/docs to open SwaggerUI. }else{Server started at http://localhost:${actualPort}. }Press ENTER key to exit.")
_ <- Console.readLine
} yield ()
yield ()
).provide(
ZLayer.succeed(Server.Config.default.port(port)),
Server.live
Expand Down

0 comments on commit 32702c4

Please sign in to comment.