Add client, client codegen, helloworld and routeguide client examples

This commit is contained in:
Lucio Franco
2019-08-17 23:31:32 -04:00
parent 3951bcf7fe
commit 2ebad2d778
26 changed files with 883 additions and 364 deletions
+32
View File
@@ -0,0 +1,32 @@
#![feature(async_await)]
use tokio::net::TcpStream;
use tower_h2::{add_origin::AddOrigin, Connection};
pub mod hello_world {
include!(concat!(env!("OUT_DIR"), "/helloworld.rs"));
tonic::client!(service = "helloworld.Greeter", proto = "self");
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let addr = "[::1]:50051".parse()?;
let io = TcpStream::connect(&addr).await?;
let origin = http::Uri::from_shared(format!("http://{}", addr).into()).unwrap();
let svc = Connection::handshake(io).await?;
let svc = AddOrigin::new(svc, origin);
let mut client = hello_world::GreeterClient::new(svc);
let request = tonic::Request::new(hello_world::HelloRequest {
name: "hello".into(),
});
let response = client.say_hello(request).await?;
println!("RESPONSE={:?}", response);
Ok(())
}