Add basic interceptor support

This commit is contained in:
Lucio Franco
2019-09-18 23:16:48 -04:00
parent 2ed69f799b
commit e419c18304
5 changed files with 91 additions and 21 deletions
+13
View File
@@ -1,6 +1,9 @@
use structopt::StructOpt;
use tonic::Server;
use tonic_interop::server;
// TODO: move GrpcService out of client since it can be used for the
// server too.
use tonic::client::GrpcService;
#[derive(StructOpt)]
struct Opts {
@@ -26,6 +29,16 @@ async fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
builder.tls(ca, key);
}
builder.interceptor_fn(|svc, req| {
println!("INBOUND REQUEST={:?}", req);
let call = svc.call(req);
async move {
let res = call.await?;
println!("OUTBOUND RESPONSE={:?}", res);
Ok(res)
}
});
builder.serve(addr, test_service).await?;
Ok(())