From 3f011d276253852c58559fc12cf9e26bd17ed853 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Thu, 12 Oct 2023 16:08:00 +0200 Subject: refactor(tvix/*store): reorganize from_url Move the channel creation depending on the string-based URL into its own block. Change-Id: I546b769acd2296b548eb966b62c495f910266df5 Reviewed-on: https://cl.tvl.fyi/c/depot/+/9706 Reviewed-by: Connor Brewster Tested-by: BuildkiteCI --- tvix/castore/src/directoryservice/grpc.rs | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) (limited to 'tvix/castore/src/directoryservice/grpc.rs') diff --git a/tvix/castore/src/directoryservice/grpc.rs b/tvix/castore/src/directoryservice/grpc.rs index 4ee2d28e97..c3207ad064 100644 --- a/tvix/castore/src/directoryservice/grpc.rs +++ b/tvix/castore/src/directoryservice/grpc.rs @@ -46,21 +46,18 @@ impl DirectoryService for GRPCDirectoryService { match url.scheme().strip_prefix("grpc+") { None => Err(crate::Error::StorageError("invalid scheme".to_string())), Some(rest) => { - if rest == "unix" { + let channel = if rest == "unix" { if url.host_str().is_some() { return Err(crate::Error::StorageError( "host may not be set".to_string(), )); } let path = url.path().to_string(); - let channel = tonic::transport::Endpoint::try_from("http://[::]:50051") // doesn't matter + tonic::transport::Endpoint::try_from("http://[::]:50051") // doesn't matter .unwrap() .connect_with_connector_lazy(tower::service_fn( move |_: tonic::transport::Uri| UnixStream::connect(path.clone()), - )); - let grpc_client = - proto::directory_service_client::DirectoryServiceClient::new(channel); - Ok(Self::from_client(grpc_client)) + )) } else { // ensure path is empty, not supported with gRPC. if !url.path().is_empty() { @@ -78,14 +75,14 @@ impl DirectoryService for GRPCDirectoryService { let s_stripped = url_str.strip_prefix("grpc+").unwrap(); url::Url::parse(s_stripped).unwrap() }; - let channel = tonic::transport::Endpoint::try_from(url.to_string()) + tonic::transport::Endpoint::try_from(url.to_string()) .unwrap() - .connect_lazy(); + .connect_lazy() + }; - let grpc_client = - proto::directory_service_client::DirectoryServiceClient::new(channel); - Ok(Self::from_client(grpc_client)) - } + Ok(Self::from_client( + proto::directory_service_client::DirectoryServiceClient::new(channel), + )) } } } -- cgit 1.4.1