Add basic interceptor support
This commit is contained in:
@@ -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(())
|
||||
|
||||
Reference in New Issue
Block a user