feat: init

This commit is contained in:
zhenyi
2026-06-07 11:30:56 +08:00
commit 563381c1ca
361 changed files with 41327 additions and 0 deletions
+84
View File
@@ -0,0 +1,84 @@
pub mod email;
pub mod repo;
use tonic::transport::{Channel, Endpoint};
#[derive(Clone)]
pub struct RepoClient {
pub repository: repo::repository_service_client::RepositoryServiceClient<Channel>,
pub commit: repo::commit_service_client::CommitServiceClient<Channel>,
pub branch: repo::branch_service_client::BranchServiceClient<Channel>,
pub tag: repo::tag_service_client::TagServiceClient<Channel>,
pub tree: repo::tree_service_client::TreeServiceClient<Channel>,
pub diff: repo::diff_service_client::DiffServiceClient<Channel>,
pub merge: repo::merge_service_client::MergeServiceClient<Channel>,
pub blame: repo::blame_service_client::BlameServiceClient<Channel>,
pub archive: repo::archive_service_client::ArchiveServiceClient<Channel>,
pub pack: repo::pack_service_client::PackServiceClient<Channel>,
}
impl RepoClient {
pub async fn connect(addr: impl Into<String>) -> Result<Self, Box<dyn std::error::Error>> {
let channel = Endpoint::from_shared(addr.into())?.connect().await?;
Ok(Self::new(channel))
}
pub fn lazy_connect(addr: impl Into<String>) -> Result<Self, Box<dyn std::error::Error>> {
let channel = Endpoint::from_shared(addr.into())?.connect_lazy();
Ok(Self::new(channel))
}
pub fn new(channel: Channel) -> Self {
Self {
repository: repo::repository_service_client::RepositoryServiceClient::new(
channel.clone(),
),
commit: repo::commit_service_client::CommitServiceClient::new(channel.clone()),
branch: repo::branch_service_client::BranchServiceClient::new(channel.clone()),
tag: repo::tag_service_client::TagServiceClient::new(channel.clone()),
tree: repo::tree_service_client::TreeServiceClient::new(channel.clone()),
diff: repo::diff_service_client::DiffServiceClient::new(channel.clone()),
merge: repo::merge_service_client::MergeServiceClient::new(channel.clone()),
blame: repo::blame_service_client::BlameServiceClient::new(channel.clone()),
archive: repo::archive_service_client::ArchiveServiceClient::new(channel.clone()),
pack: repo::pack_service_client::PackServiceClient::new(channel),
}
}
}
#[derive(Clone)]
pub struct EmailClient {
inner: email::email_service_client::EmailServiceClient<Channel>,
}
impl EmailClient {
pub async fn connect(addr: impl Into<String>) -> Result<Self, Box<dyn std::error::Error>> {
let channel = Endpoint::from_shared(addr.into())?.connect().await?;
Ok(Self::new(channel))
}
pub fn lazy_connect(addr: impl Into<String>) -> Result<Self, Box<dyn std::error::Error>> {
let channel = Endpoint::from_shared(addr.into())?.connect_lazy();
Ok(Self::new(channel))
}
pub fn new(channel: Channel) -> Self {
Self {
inner: email::email_service_client::EmailServiceClient::new(channel),
}
}
}
impl std::ops::Deref for EmailClient {
type Target = email::email_service_client::EmailServiceClient<Channel>;
fn deref(&self) -> &Self::Target {
&self.inner
}
}
impl std::ops::DerefMut for EmailClient {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.inner
}
}