FEAT: Refactor allowing multiple DNS Providers
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
2024-03-15 23:16:23 +13:00
parent a977adf929
commit 17014eeae1
10 changed files with 56416 additions and 75 deletions

View File

@@ -0,0 +1,29 @@
package dns_resolver
import (
"context"
"fmt"
"net"
"os"
"time"
)
func ResolveHostname(host string, dns_resolver_ip string) net.IP {
r := &net.Resolver{
PreferGo: true,
Dial: func(ctx context.Context, network, address string) (net.Conn, error) {
d := net.Dialer{
Timeout: time.Millisecond * time.Duration(10000),
}
return d.DialContext(ctx, network, dns_resolver_ip+":53")
},
}
ips, err := r.LookupHost(context.Background(), host)
if err != nil {
fmt.Fprintf(os.Stderr, "Could not get IPs: %v\n", err)
os.Exit(1)
}
return net.ParseIP(ips[len(ips)-1])
}