Skip to content

Commit

Permalink
refactor: Deduplicate the strategy logic
Browse files Browse the repository at this point in the history
  • Loading branch information
PurpleBooth committed Aug 21, 2024
1 parent 11a7cff commit 2916998
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,41 +127,33 @@ async fn main() -> Result<()> {

#[allow(clippy::redundant_pub_crate)]
async fn find_wan_ip(strategy: IpVersion) -> Result<MyIps> {
let lookup_ip_strategy = match strategy {
Ipv4 => LookupIpStrategy::Ipv4Only,
Ipv6 => LookupIpStrategy::Ipv6Only,
};
let ns_ip = tokio::select! {
ns_ip = async {
resolver_ip(
GOOGLE_NS1,
match strategy {
Ipv4 => {LookupIpStrategy::Ipv4Only}
Ipv6 => {LookupIpStrategy::Ipv6Only}
}
lookup_ip_strategy
).await
} => ns_ip,
ns_ip = async {
resolver_ip(
GOOGLE_NS2,
match strategy {
Ipv4 => {LookupIpStrategy::Ipv4Only}
Ipv6 => {LookupIpStrategy::Ipv6Only}
}
lookup_ip_strategy
).await
} => ns_ip,
ns_ip = async {
resolver_ip(
GOOGLE_NS3,
match strategy {
Ipv4 => {LookupIpStrategy::Ipv4Only}
Ipv6 => {LookupIpStrategy::Ipv6Only}
}
lookup_ip_strategy
).await
} => ns_ip,
ns_ip = async {
resolver_ip(
GOOGLE_NS4,
match strategy {
Ipv4 => {LookupIpStrategy::Ipv4Only}
Ipv6 => {LookupIpStrategy::Ipv6Only}
}
lookup_ip_strategy
).await
} => ns_ip,
}?;
Expand Down

0 comments on commit 2916998

Please sign in to comment.