Simplify resolving of location addresses

This commit is contained in:
Andrey Golovizin 2023-04-16 00:11:02 +02:00
parent 0d30090e5b
commit d909462cc4

View file

@ -33,15 +33,8 @@ pub(crate) struct Location {
impl Location { impl Location {
pub(crate) fn get_endpoint(&self) -> anyhow::Result<SocketAddr> { pub(crate) fn get_endpoint(&self) -> anyhow::Result<SocketAddr> {
let endpoint_addr_with_port: String; (self.pool.as_str(), 51820)
let endpoint_addr = if self.pool.contains(':') { .to_socket_addrs()?
&self.pool
} else {
endpoint_addr_with_port = format!("{}:51820", self.pool);
&endpoint_addr_with_port
};
let mut endpoints = endpoint_addr.to_socket_addrs()?;
endpoints
.next() .next()
.ok_or_else(|| anyhow!("no valid endpoint address")) .ok_or_else(|| anyhow!("no valid endpoint address"))
} }