forked from Deuxfleurs/garage
resolve domain to multiple addresses
And warn instead of failling when a domain can't be resolved
This commit is contained in:
parent
c8a7ce5cdf
commit
f17cb6c969
1 changed files with 17 additions and 10 deletions
|
@ -90,14 +90,21 @@ where
|
||||||
{
|
{
|
||||||
use std::net::ToSocketAddrs;
|
use std::net::ToSocketAddrs;
|
||||||
|
|
||||||
let mut res = vec![];
|
Ok(<Vec<&str>>::deserialize(deserializer)?
|
||||||
for s in <Vec<&str>>::deserialize(deserializer)? {
|
.iter()
|
||||||
res.push(
|
.filter_map(|&name| {
|
||||||
s.to_socket_addrs()
|
name.to_socket_addrs()
|
||||||
.map_err(|_| de::Error::custom("could not resolve to a socket address"))?
|
.map(|iter| (name, iter))
|
||||||
.next()
|
.map_err(|_| warn!("Error resolving \"{}\"", name))
|
||||||
.ok_or(de::Error::custom("could not resolve to a socket address"))?,
|
.ok()
|
||||||
);
|
})
|
||||||
}
|
.map(|(name, iter)| {
|
||||||
Ok(res)
|
let v = iter.collect::<Vec<_>>();
|
||||||
|
if v.is_empty() {
|
||||||
|
warn!("Error resolving \"{}\"", name)
|
||||||
|
}
|
||||||
|
v
|
||||||
|
})
|
||||||
|
.flatten()
|
||||||
|
.collect())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue