burrow/burrow-gtk/src/daemon.rs
2024-08-17 10:57:18 -07:00

17 lines
530 B
Rust

use anyhow::Result;
use hyper_util::rt::TokioIo;
use tokio::net::UnixStream;
use tonic::transport::{Channel, Endpoint, Uri};
use tower::service_fn;
const BURROW_RPC_SOCKET_PATH: &str = "/run/burrow.sock";
pub async fn daemon_connect() -> Result<Channel> {
Ok(Endpoint::try_from("http://[::]:50051")?
.connect_with_connector(service_fn(|_: Uri| async {
Ok::<_, std::io::Error>(TokioIo::new(
UnixStream::connect(BURROW_RPC_SOCKET_PATH).await?,
))
}))
.await?)
}