diff options
author | Ilion Beyst <ilion.beyst@gmail.com> | 2022-06-06 14:25:56 +0200 |
---|---|---|
committer | Ilion Beyst <ilion.beyst@gmail.com> | 2022-06-06 14:25:56 +0200 |
commit | 2f915af91982073644be94bb2c68e095ffd35596 (patch) | |
tree | c59eb7330c9472fb9da02615cc08fb33e842961c /planetwars-client | |
parent | d0faec7d1f4deb132554db7f946df4b9d4e9711b (diff) | |
download | planetwars.dev-2f915af91982073644be94bb2c68e095ffd35596.tar.xz planetwars.dev-2f915af91982073644be94bb2c68e095ffd35596.zip |
send player_id through request metadata
Diffstat (limited to 'planetwars-client')
-rw-r--r-- | planetwars-client/src/main.rs | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/planetwars-client/src/main.rs b/planetwars-client/src/main.rs index d995ebc..0fbcdb2 100644 --- a/planetwars-client/src/main.rs +++ b/planetwars-client/src/main.rs @@ -6,13 +6,21 @@ use pb::bot_api_service_client::BotApiServiceClient; use tokio_stream::wrappers::UnboundedReceiverStream; use tokio::sync::mpsc; +use tonic::{metadata::MetadataValue, transport::Channel, Request}; #[tokio::main] async fn main() { - let mut client = BotApiServiceClient::connect("http://localhost:50051") + let channel = Channel::from_static("http://localhost:50051") + .connect() .await .unwrap(); + let mut client = BotApiServiceClient::with_interceptor(channel, |mut req: Request<()>| { + let player_id: MetadataValue<_> = "test_player".parse().unwrap(); + req.metadata_mut().insert("player_id", player_id); + Ok(req) + }); + let (tx, rx) = mpsc::unbounded_channel(); let mut stream = client .connect_bot(UnboundedReceiverStream::new(rx)) |