Add basic interceptor support
This commit is contained in:
@@ -22,6 +22,7 @@ http = "0.1"
|
||||
futures-core-preview = "=0.3.0-alpha.18"
|
||||
futures-util-preview = "=0.3.0-alpha.18"
|
||||
async-stream = "0.1.1"
|
||||
tower = "0.3.0-alpha.1a"
|
||||
|
||||
console = "0.7"
|
||||
structopt = "0.2"
|
||||
|
||||
@@ -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