use crate::os::{register_service, RegisteredDnsService, RegistrationError};
use std::collections::HashMap;
pub type Result<T, E = RegistrationError> = std::result::Result<T, E>;
pub struct DNSServiceBuilder {
pub(crate) regtype: String,
pub(crate) name: Option<String>,
pub(crate) domain: Option<String>,
pub(crate) host: Option<String>,
pub(crate) port: u16,
pub(crate) txt: Option<HashMap<String, String>>,
}
impl DNSServiceBuilder {
pub fn new(regtype: &str, port: u16) -> DNSServiceBuilder {
DNSServiceBuilder {
regtype: String::from(regtype),
name: None,
domain: None,
host: None,
port,
txt: None,
}
}
pub fn with_name(mut self, name: &str) -> DNSServiceBuilder {
self.name = Some(String::from(name));
self
}
pub fn with_domain(mut self, domain: &str) -> DNSServiceBuilder {
self.domain = Some(String::from(domain));
self
}
pub fn with_host(mut self, host: &str) -> DNSServiceBuilder {
self.host = Some(String::from(host));
self
}
pub fn with_txt_record(mut self, txt: HashMap<String, String>) -> DNSServiceBuilder {
self.txt = Some(txt);
self
}
pub fn with_key_value(mut self, key: String, value: String) -> DNSServiceBuilder {
let mut kv = self.txt.take().unwrap_or_default();
kv.insert(key, value);
self.txt = Some(kv);
self
}
pub fn register(self) -> Result<RegisteredDnsService> {
register_service(self)
}
}