package resolver import ( "errors" "net" "strings" ) func ClassifyDNSError(err error) string { if err == nil { return "other" } var dnsErr *net.DNSError if errors.As(err, &dnsErr) { if dnsErr.IsNotFound { return "nxdomain" } if dnsErr.IsTimeout { return "timeout" } if dnsErr.IsTemporary { return "temporary" } } msg := strings.ToLower(err.Error()) switch { case strings.Contains(msg, "no such host"), strings.Contains(msg, "nxdomain"): return "nxdomain" case strings.Contains(msg, "i/o timeout"), strings.Contains(msg, "timeout"): return "timeout" case strings.Contains(msg, "temporary"): return "temporary" default: return "other" } } func SplitDNS(dns string) (string, string) { if strings.Contains(dns, "#") { parts := strings.SplitN(dns, "#", 2) host := strings.TrimSpace(parts[0]) port := strings.TrimSpace(parts[1]) if host == "" { host = "127.0.0.1" } if port == "" { port = "53" } return host, port } return strings.TrimSpace(dns), "" }