1use crate::{Detector, MetaDetector};
2use detector::{Meta, MetaKey, Service, ServiceKey};
3use std::time::Duration;
4
5#[derive(Clone)]
6pub struct Builder {
7 client: etcd_client::Client,
8}
9
10impl Builder {
11 pub async fn connect<E: AsRef<str>, S: AsRef<[E]>>(
13 endpoints: S,
14 ) -> Result<Builder, etcd_client::Error> {
15 let options = Some(
16 etcd_client::ConnectOptions::new()
17 .with_keep_alive(Duration::from_secs(5), Duration::from_secs(10)),
18 );
19 let client = etcd_client::Client::connect(endpoints, options).await?;
20 Ok(Builder { client })
21 }
22
23 pub fn detector(&self, service: Service) -> Detector {
25 Detector::new(self.client.clone(), service)
26 }
27
28 pub fn detector_from_key(&self, key: ServiceKey) -> Detector {
30 Detector::new(self.client.clone(), Service::from_key(key))
31 }
32
33 pub fn meta_detector(&self, meta: Meta) -> MetaDetector {
35 MetaDetector::new(self.client.clone(), meta)
36 }
37
38 pub fn meta_detector_from_key(&self, key: MetaKey) -> MetaDetector {
40 MetaDetector::new(self.client.clone(), Meta::from_key(key))
41 }
42}