diff options
author | Ilion Beyst <ilion.beyst@gmail.com> | 2022-06-01 20:19:13 +0200 |
---|---|---|
committer | Ilion Beyst <ilion.beyst@gmail.com> | 2022-06-01 20:19:13 +0200 |
commit | 0f80b196149a0fb75d84b61c8bbbeb9a71267129 (patch) | |
tree | cf353555411c2612f92a861acf97686df5fb51c5 | |
parent | af5cd69f7b60c07c4830f2eca9b8b1544c7c4972 (diff) | |
download | planetwars.dev-0f80b196149a0fb75d84b61c8bbbeb9a71267129.tar.xz planetwars.dev-0f80b196149a0fb75d84b61c8bbbeb9a71267129.zip |
set up stub grpc client
-rw-r--r-- | Cargo.toml | 2 | ||||
-rw-r--r-- | planetwars-client/Cargo.toml | 14 | ||||
-rw-r--r-- | planetwars-client/build.rs | 9 | ||||
-rw-r--r-- | planetwars-client/src/main.rs | 21 |
4 files changed, 45 insertions, 1 deletions
@@ -3,6 +3,6 @@ members = [ "planetwars-rules", "planetwars-matchrunner", - "planetwars-cli", "planetwars-server", + "planetwars-client", ] diff --git a/planetwars-client/Cargo.toml b/planetwars-client/Cargo.toml new file mode 100644 index 0000000..10de887 --- /dev/null +++ b/planetwars-client/Cargo.toml @@ -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" diff --git a/planetwars-client/build.rs b/planetwars-client/build.rs new file mode 100644 index 0000000..acabd08 --- /dev/null +++ b/planetwars-client/build.rs @@ -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(()) +} diff --git a/planetwars-client/src/main.rs b/planetwars-client/src/main.rs new file mode 100644 index 0000000..9d9bdab --- /dev/null +++ b/planetwars-client/src/main.rs @@ -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); +} |