use std::time::Duration;
#[derive(Default, Clone, Debug)]
pub struct StooConfig{
pub(crate) url: &'static str,
default_namespace: &'static str,
default_profile: &'static str,
pub(crate) connect_timeout: Duration,
pub(crate) response_timeout: Duration,
pub(crate) domain: &'static str,
pub(crate) ca_certificate: &'static str
}
impl From<&'static str> for StooConfig {
fn from(url: &'static str) -> Self {
Self{
url,
default_namespace: "",
default_profile: "",
connect_timeout: Duration::from_millis(10000),
response_timeout: Duration::from_millis(30000),
domain: "",
ca_certificate: "",
}
}
}
#[allow(dead_code)]
impl StooConfig{
pub fn connect_timeout(self, duration: Duration) -> Self {
StooConfig {
connect_timeout: duration,
..self
}
}
pub fn response_timeout(self, duration: Duration) -> Self {
StooConfig {
response_timeout: duration,
..self
}
}
pub fn default_namespace(self, default_namespace: &'static str) -> Self {
StooConfig {
default_namespace,
..self
}
}
pub fn default_profile(self, default_profile: &'static str) -> Self {
StooConfig {
default_profile,
..self
}
}
pub fn domain(self, domain: &'static str) -> Self {
StooConfig {
domain,
..self
}
}
pub fn ca_certificate(self, ca_certificate: &'static str) -> Self {
StooConfig {
ca_certificate,
..self
}
}
pub fn get_default_namespace(self) -> Result<&'static str, String>{
if self.default_namespace == ""{
return Err(String::from("default_namespace is empty"))
}
return Ok(self.default_namespace)
}
pub fn get_default_profile(self) -> Result<&'static str, String>{
if self.default_profile == ""{
return Err(String::from("default_namespace is empty"))
}
return Ok(self.default_profile)
}
}