platform: modularize api/gui, add docs-tests-web foundation, and refresh root config
This commit is contained in:
52
selective-vpn-api/app/resolver/dns_helpers.go
Normal file
52
selective-vpn-api/app/resolver/dns_helpers.go
Normal file
@@ -0,0 +1,52 @@
|
||||
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), ""
|
||||
}
|
||||
Reference in New Issue
Block a user