set up stub grpc client
This commit is contained in:
parent
af5cd69f7b
commit
0f80b19614
4 changed files with 45 additions and 1 deletions
|
@ -3,6 +3,6 @@
|
|||
members = [
|
||||
"planetwars-rules",
|
||||
"planetwars-matchrunner",
|
||||
"planetwars-cli",
|
||||
"planetwars-server",
|
||||
"planetwars-client",
|
||||
]
|
||||
|
|
14
planetwars-client/Cargo.toml
Normal file
14
planetwars-client/Cargo.toml
Normal file
|
@ -0,0 +1,14 @@
|
|||
[package]
|
||||
name = "planetwars-client"
|
||||
version = "0.0.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
tokio = { version = "1.15", features = ["full"] }
|
||||
prost = "0.10"
|
||||
tonic = "0.7.2"
|
||||
|
||||
[build-dependencies]
|
||||
tonic-build = "0.7.2"
|
9
planetwars-client/build.rs
Normal file
9
planetwars-client/build.rs
Normal file
|
@ -0,0 +1,9 @@
|
|||
extern crate tonic_build;
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
tonic_build::configure()
|
||||
.build_server(false)
|
||||
.build_client(true)
|
||||
.compile(&["../proto/bot_api.proto"], &["../proto"])?;
|
||||
Ok(())
|
||||
}
|
21
planetwars-client/src/main.rs
Normal file
21
planetwars-client/src/main.rs
Normal file
|
@ -0,0 +1,21 @@
|
|||
pub mod pb {
|
||||
tonic::include_proto!("grpc.planetwars.bot_api");
|
||||
}
|
||||
|
||||
use pb::test_service_client::TestServiceClient;
|
||||
use pb::{Hello, HelloResponse};
|
||||
use tonic::Response;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
let mut client = TestServiceClient::connect("http://localhost:50051")
|
||||
.await
|
||||
.unwrap();
|
||||
let response: Response<HelloResponse> = client
|
||||
.greet(Hello {
|
||||
hello_message: "robbe".to_string(),
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
println!("{}", response.get_ref().response);
|
||||
}
|
Loading…
Reference in a new issue