don't store nil slice to db

This commit is contained in:
Seraphim Strub 2024-07-17 21:05:26 +00:00
parent 739a68f292
commit a588d9aecc

View file

@ -60,6 +60,7 @@ func getNameserverForTLD(tld string) ([]string, error) {
}
func queryTLDNamserver(fqdn, tldServer string) ([]string, error) {
nameservers := []string{}
// Create a new DNS message
m := new(dns.Msg)
// Set the question section of the message with the fqdn and query type
@ -71,16 +72,15 @@ func queryTLDNamserver(fqdn, tldServer string) ([]string, error) {
// Send the DNS query to the TLD server
r, _, err := c.Exchange(m, tldServer)
if err != nil {
return nil, fmt.Errorf("dns query error: %v", err)
return nameservers, fmt.Errorf("dns query error: %v", err)
}
// Check for response errors
if r.Rcode != dns.RcodeSuccess {
return nil, fmt.Errorf("failed to get a valid response for %v: %v", fqdn, r.Rcode)
return nameservers, fmt.Errorf("failed to get a valid response for %v: %v", fqdn, r.Rcode)
}
// Print the nameservers from the response
nameservers := []string{}
for _, ans := range r.Ns {
if ns, ok := ans.(*dns.NS); ok {
nameservers = append(nameservers, strings.ToLower(ns.Ns))