chore(docs): Add helloworld tutorial (#80)

This commit is contained in:
Matt Conway
2019-10-22 19:03:39 -04:00
committed by Lucio Franco
parent 9b0613a16d
commit 8ebedcde2f
3 changed files with 318 additions and 9 deletions
+1 -1
View File
@@ -9,7 +9,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut client = GreeterClient::connect("http://[::1]:50051")?;
let request = tonic::Request::new(HelloRequest {
name: "hello".into(),
name: "Tonic".into(),
});
let response = client.say_hello(request).await?;
+2 -8
View File
@@ -10,9 +10,7 @@ use hello_world::{
};
#[derive(Default)]
pub struct MyGreeter {
data: String,
}
pub struct MyGreeter {}
#[tonic::async_trait]
impl Greeter for MyGreeter {
@@ -22,12 +20,8 @@ impl Greeter for MyGreeter {
) -> Result<Response<HelloReply>, Status> {
println!("Got a request: {:?}", request);
let string = &self.data;
println!("My data: {:?}", string);
let reply = hello_world::HelloReply {
message: "Zomg, it works!".into(),
message: format!("Hello {}!", request.into_inner().name).into(),
};
Ok(Response::new(reply))
}