diff options
author | Ilion Beyst <ilion.beyst@gmail.com> | 2022-05-31 21:08:56 +0200 |
---|---|---|
committer | Ilion Beyst <ilion.beyst@gmail.com> | 2022-05-31 21:08:56 +0200 |
commit | af5cd69f7b60c07c4830f2eca9b8b1544c7c4972 (patch) | |
tree | 8abe8829f8517299002a72bfeac84cd266f5d550 /planetwars-server/src | |
parent | ef19e3a9e79c85753f75b8f87a06b67c574a72ee (diff) | |
download | planetwars.dev-af5cd69f7b60c07c4830f2eca9b8b1544c7c4972.tar.xz planetwars.dev-af5cd69f7b60c07c4830f2eca9b8b1544c7c4972.zip |
set up gprc server
Diffstat (limited to 'planetwars-server/src')
-rw-r--r-- | planetwars-server/src/modules/bot_api.rs | 30 | ||||
-rw-r--r-- | planetwars-server/src/modules/mod.rs | 1 |
2 files changed, 31 insertions, 0 deletions
diff --git a/planetwars-server/src/modules/bot_api.rs b/planetwars-server/src/modules/bot_api.rs new file mode 100644 index 0000000..1941136 --- /dev/null +++ b/planetwars-server/src/modules/bot_api.rs @@ -0,0 +1,30 @@ +pub mod pb { + tonic::include_proto!("grpc.planetwars.bot_api"); +} + +use std::net::SocketAddr; + +use tonic; +use tonic::transport::Server; +use tonic::{Request, Response, Status}; + +pub struct BotApiServer {} + +#[tonic::async_trait] +impl pb::test_service_server::TestService for BotApiServer { + async fn greet(&self, req: Request<pb::Hello>) -> Result<Response<pb::HelloResponse>, Status> { + Ok(Response::new(pb::HelloResponse { + response: format!("hallo {}", req.get_ref().hello_message), + })) + } +} + +pub async fn run_bot_api() { + let server = BotApiServer {}; + let addr = SocketAddr::from(([127, 0, 0, 1], 50051)); + Server::builder() + .add_service(pb::test_service_server::TestServiceServer::new(server)) + .serve(addr) + .await + .unwrap() +} diff --git a/planetwars-server/src/modules/mod.rs b/planetwars-server/src/modules/mod.rs index bea28e0..43c2507 100644 --- a/planetwars-server/src/modules/mod.rs +++ b/planetwars-server/src/modules/mod.rs @@ -1,5 +1,6 @@ // This module implements general domain logic, not directly // tied to the database or API layers. +pub mod bot_api; pub mod bots; pub mod matches; pub mod ranking; |