replace closure with auth_header function

I AM SO COOL
This commit is contained in:
2026-04-13 08:46:13 +02:00
parent 4a73819d67
commit 378044a41c

View File

@@ -9,13 +9,9 @@ mod client;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
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(
channel,
move |mut req: Request<()>| {
req.metadata_mut().insert("authorization", token.clone());
Ok(req)
},
auth_header
);
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> {
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");