use std::net::SocketAddr;
pub(crate) enum Resolver {
System,
#[cfg(any(test, feature = "test-support"))]
Static(std::collections::HashMap<String, Vec<std::net::IpAddr>>),
}
impl Resolver {
pub(crate) async fn resolve(
&self,
host: &str,
port: u16,
) -> Result<Vec<SocketAddr>, std::io::Error> {
match self {
Resolver::System => tokio::net::lookup_host((host, port))
.await
.map(|it| it.collect()),
#[cfg(any(test, feature = "test-support"))]
Resolver::Static(map) => Ok(map
.get(host)
.map(|ips| ips.iter().map(|ip| SocketAddr::new(*ip, port)).collect())
.unwrap_or_default()),
}
}
}