Convert HostPortOrFile error to var (#5058)

Convert "no nameservers found" error on parse.HostPortOrFile() to an
exported var for use with `errors.Is()`.

Signed-off-by: SuperQ <superq@gmail.com>
This commit is contained in:
Ben Kochie 2021-12-23 18:02:28 +01:00 committed by GitHub
parent b53aac992a
commit 74f3bea50f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,6 +1,7 @@
package parse package parse
import ( import (
"errors"
"fmt" "fmt"
"net" "net"
"os" "os"
@ -11,6 +12,9 @@ import (
"github.com/miekg/dns" "github.com/miekg/dns"
) )
// ErrNoNameservers is returned by HostPortOrFile if no servers can be parsed.
var ErrNoNameservers = errors.New("no nameservers found")
// Strips the zone, but preserves any port that comes after the zone // Strips the zone, but preserves any port that comes after the zone
func stripZone(host string) string { func stripZone(host string) string {
if strings.Contains(host, "%") { if strings.Contains(host, "%") {
@ -70,7 +74,7 @@ func HostPortOrFile(s ...string) ([]string, error) {
servers = append(servers, h) servers = append(servers, h)
} }
if len(servers) == 0 { if len(servers) == 0 {
return servers, fmt.Errorf("no nameservers found") return servers, ErrNoNameservers
} }
return servers, nil return servers, nil
} }