From af5cd69f7b60c07c4830f2eca9b8b1544c7c4972 Mon Sep 17 00:00:00 2001 From: Ilion Beyst Date: Tue, 31 May 2022 21:08:56 +0200 Subject: set up gprc server --- planetwars-server/src/modules/bot_api.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 planetwars-server/src/modules/bot_api.rs (limited to 'planetwars-server/src/modules/bot_api.rs') 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) -> Result, 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() +} -- cgit v1.2.3