mirror of
https://github.com/qdm12/ddns-updater.git
synced 2026-04-05 08:54:09 -04:00
chore(update): use newer LookupNetIP resolver function to use netip.Addr directly
This commit is contained in:
@@ -2,7 +2,6 @@ package update
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
"net/netip"
|
||||
|
||||
"github.com/qdm12/ddns-updater/internal/healthchecksio"
|
||||
@@ -26,7 +25,7 @@ type Database interface {
|
||||
}
|
||||
|
||||
type LookupIPer interface {
|
||||
LookupIP(ctx context.Context, network, host string) (ips []net.IP, err error)
|
||||
LookupNetIP(ctx context.Context, network, host string) (ips []netip.Addr, err error)
|
||||
}
|
||||
|
||||
type ShoutrrrClient interface {
|
||||
|
||||
@@ -66,20 +66,20 @@ func (s *Service) lookupIPsResilient(ctx context.Context, hostname string, tries
|
||||
func (s *Service) lookupIPs(ctx context.Context, hostname string) (
|
||||
ipv4, ipv6 []netip.Addr, err error,
|
||||
) {
|
||||
netIPs, err := s.resolver.LookupIP(ctx, "ip", hostname)
|
||||
ips, err := s.resolver.LookupNetIP(ctx, "ip", hostname)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
ipv4 = make([]netip.Addr, 0, len(netIPs))
|
||||
ipv6 = make([]netip.Addr, 0, len(netIPs))
|
||||
for _, netIP := range netIPs {
|
||||
ipv4 = make([]netip.Addr, 0, len(ips))
|
||||
ipv6 = make([]netip.Addr, 0, len(ips))
|
||||
for _, ip := range ips {
|
||||
switch {
|
||||
case netIP == nil:
|
||||
case netIP.To4() != nil:
|
||||
ipv4 = append(ipv4, netip.AddrFrom4([4]byte(netIP.To4())))
|
||||
case !ip.IsValid():
|
||||
case ip.Is4():
|
||||
ipv4 = append(ipv4, ip)
|
||||
default: // IPv6
|
||||
ipv6 = append(ipv6, netip.AddrFrom16([16]byte(netIP.To16())))
|
||||
ipv6 = append(ipv6, ip)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user