use crate::{Detector, MetaDetector};
use detector::{Meta, MetaKey, Service, ServiceKey};
use std::time::Duration;
#[derive(Clone)]
pub struct Builder {
client: etcd_client::Client,
}
impl Builder {
pub async fn connect<E: AsRef<str>, S: AsRef<[E]>>(
endpoints: S,
) -> Result<Builder, etcd_client::Error> {
let options = Some(
etcd_client::ConnectOptions::new()
.with_keep_alive(Duration::from_secs(5), Duration::from_secs(10)),
);
let client = etcd_client::Client::connect(endpoints, options).await?;
Ok(Builder { client })
}
pub fn detector(&self, service: Service) -> Detector {
Detector::new(self.client.clone(), service)
}
pub fn detector_from_key(&self, key: ServiceKey) -> Detector {
Detector::new(self.client.clone(), Service::from_key(key))
}
pub fn meta_detector(&self, meta: Meta) -> MetaDetector {
MetaDetector::new(self.client.clone(), meta)
}
pub fn meta_detector_from_key(&self, key: MetaKey) -> MetaDetector {
MetaDetector::new(self.client.clone(), Meta::from_key(key))
}
}