replace closure with auth_header function
I AM SO COOL
This commit is contained in:
@@ -9,13 +9,9 @@ mod client;
|
|||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let channel = Channel::from_static("dns:///youtube.googleapis.com:443").connect().await?;
|
let channel = Channel::from_static("dns:///youtube.googleapis.com:443").connect().await?;
|
||||||
let token: MetadataValue<_> = "Bearer my-secret-token".parse()?;
|
|
||||||
let mut client = V3DataLiveChatMessageServiceClient::with_interceptor(
|
let mut client = V3DataLiveChatMessageServiceClient::with_interceptor(
|
||||||
channel,
|
channel,
|
||||||
move |mut req: Request<()>| {
|
auth_header
|
||||||
req.metadata_mut().insert("authorization", token.clone());
|
|
||||||
Ok(req)
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
|
|
||||||
let request = tonic::Request::new(LiveChatMessageListRequest {
|
let request = tonic::Request::new(LiveChatMessageListRequest {
|
||||||
@@ -36,7 +32,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
|
|
||||||
async fn auth_header(mut req: Request<()>) -> Result<Request<()>, InvalidMetadataValue> {
|
async fn auth_header(mut req: Request<()>) -> Result<Request<()>, InvalidMetadataValue> {
|
||||||
|
|
||||||
let token: MetadataValue<_> = "Bearer my-secret-token".parse()?;
|
let token: MetadataValue<_> = "Bearer my-secret-token".parse().expect("failed to parse token");
|
||||||
|
|
||||||
|
|
||||||
req.metadata_mut().insert("x-goog-api-key", token).expect("WHAT");
|
req.metadata_mut().insert("x-goog-api-key", token).expect("WHAT");
|
||||||
|
|||||||
Reference in New Issue
Block a user