WIP: rewrote runtime.rs using match to convey intent better
This commit is contained in:
parent
beefcd7ade
commit
f5ac36e21f
1 changed files with 45 additions and 17 deletions
|
@ -62,10 +62,14 @@ impl RuntimeConfig {
|
|||
|
||||
impl RuntimeConfigConsul {
|
||||
pub(super) fn new(opts: ConfigOptsConsul) -> Result<Self> {
|
||||
let node_name = opts
|
||||
.node_name
|
||||
.expect("'DIPLONAT_CONSUL_NODE_NAME' is required");
|
||||
let url = opts.url.unwrap_or(super::CONSUL_URL.to_string());
|
||||
let node_name = match opts.node_name {
|
||||
Some(n) => n,
|
||||
_ => return Err(anyhow!("'DIPLONAT_CONSUL_NODE_NAME' is required")),
|
||||
};
|
||||
let url = match opts.url {
|
||||
Some(url) => url,
|
||||
_ => super::CONSUL_URL.to_string(),
|
||||
};
|
||||
|
||||
Ok(Self { node_name, url })
|
||||
}
|
||||
|
@ -75,11 +79,16 @@ impl RuntimeConfigAcme {
|
|||
pub fn new(opts: ConfigOptsAcme) -> Result<Option<Self>> {
|
||||
if !opts.enable {
|
||||
return Ok(None)
|
||||
}
|
||||
};
|
||||
|
||||
let email = opts
|
||||
.email
|
||||
.expect("'DIPLONAT_ACME_EMAIL' is required if ACME is enabled");
|
||||
let email = match opts.email {
|
||||
Some(email) => email,
|
||||
_ => {
|
||||
return Err(anyhow!(
|
||||
"'DIPLONAT_ACME_EMAIL' is required if ACME is enabled"
|
||||
))
|
||||
}
|
||||
};
|
||||
|
||||
Ok(Some(Self { email }))
|
||||
}
|
||||
|
@ -91,7 +100,13 @@ impl RuntimeConfigFirewall {
|
|||
return Ok(None)
|
||||
}
|
||||
|
||||
let refresh_time = Duration::from_secs(opts.refresh_time.unwrap_or(super::REFRESH_TIME).into());
|
||||
let refresh_time = Duration::from_secs(
|
||||
match opts.refresh_time {
|
||||
Some(t) => t,
|
||||
_ => super::REFRESH_TIME,
|
||||
}
|
||||
.into(),
|
||||
);
|
||||
|
||||
Ok(Some(Self { refresh_time }))
|
||||
}
|
||||
|
@ -103,16 +118,29 @@ impl RuntimeConfigIgd {
|
|||
return Ok(None)
|
||||
}
|
||||
|
||||
let private_ip = opts
|
||||
.private_ip
|
||||
.expect("'DIPLONAT_IGD_PRIVATE_IP' is required if IGD is enabled");
|
||||
let private_ip = match opts.private_ip {
|
||||
Some(ip) => ip,
|
||||
_ => {
|
||||
return Err(anyhow!(
|
||||
"'DIPLONAT_IGD_PRIVATE_IP' is required if IGD is enabled"
|
||||
))
|
||||
}
|
||||
};
|
||||
|
||||
let expiration_time = Duration::from_secs(
|
||||
opts
|
||||
.expiration_time
|
||||
.unwrap_or(super::EXPIRATION_TIME)
|
||||
.into(),
|
||||
match opts.expiration_time {
|
||||
Some(t) => t.into(),
|
||||
_ => super::EXPIRATION_TIME,
|
||||
}
|
||||
.into(),
|
||||
);
|
||||
let refresh_time = Duration::from_secs(
|
||||
match opts.refresh_time {
|
||||
Some(t) => t,
|
||||
_ => super::REFRESH_TIME,
|
||||
}
|
||||
.into(),
|
||||
);
|
||||
let refresh_time = Duration::from_secs(opts.refresh_time.unwrap_or(super::REFRESH_TIME).into());
|
||||
|
||||
if refresh_time.as_secs() * 2 > expiration_time.as_secs() {
|
||||
return Err(anyhow!(
|
||||
|
|
Loading…
Reference in a new issue