-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add GrpService, update GrpcClient and GrpcServices
- Loading branch information
Showing
5 changed files
with
104 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
server/src/main/scala/app/softnetwork/api/server/GrpcService.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package app.softnetwork.api.server | ||
|
||
import akka.actor.typed.ActorSystem | ||
import akka.http.scaladsl.model.{HttpRequest, HttpResponse} | ||
import akka.http.scaladsl.server.Directives | ||
import akka.http.scaladsl.server.Route | ||
|
||
import scala.concurrent.Future | ||
|
||
trait GrpcService extends Directives { | ||
|
||
def grpcService: ActorSystem[_] => PartialFunction[HttpRequest, Future[HttpResponse]] | ||
|
||
def route: ActorSystem[_] => Route = system => handle(grpcService(system)) | ||
} |
18 changes: 4 additions & 14 deletions
18
server/src/main/scala/app/softnetwork/api/server/GrpcServices.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,13 @@ | ||
package app.softnetwork.api.server | ||
|
||
import akka.actor.typed.ActorSystem | ||
import akka.grpc.scaladsl.ServiceHandler | ||
import akka.http.scaladsl.model.{HttpRequest, HttpResponse} | ||
import akka.http.scaladsl.server.Directives.handle | ||
import akka.http.scaladsl.server.Route | ||
import akka.http.scaladsl.server.{Route, RouteConcatenation} | ||
|
||
import scala.concurrent.Future | ||
trait GrpcServices extends RouteConcatenation { | ||
|
||
trait GrpcServices { | ||
|
||
def grpcServices: ActorSystem[_] => Seq[PartialFunction[HttpRequest, Future[HttpResponse]]] = _ => | ||
Seq.empty | ||
def grpcServices: ActorSystem[_] => Seq[GrpcService] = _ => Seq.empty | ||
|
||
final def grpcRoutes: ActorSystem[_] => Route = system => | ||
handle( | ||
ServiceHandler.concatOrNotFound( | ||
grpcServices(system): _* | ||
) | ||
) | ||
concat(grpcServices(system).map(_.route(system)): _*) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters