aboutsummaryrefslogtreecommitdiff
path: root/plugin/normalize.go
diff options
context:
space:
mode:
authorGravatar Miek Gieben <miek@miek.nl> 2018-09-19 07:29:37 +0100
committerGravatar GitHub <noreply@github.com> 2018-09-19 07:29:37 +0100
commitc349446a23440b336f4ca21900cce4d6a031cdf5 (patch)
tree983ab79eac59d59e36dfbf4a29fcf1bd811110d5 /plugin/normalize.go
parent2f1223c36a0294cd07e299aaa792a0b3f51f687a (diff)
downloadcoredns-c349446a23440b336f4ca21900cce4d6a031cdf5.tar.gz
coredns-c349446a23440b336f4ca21900cce4d6a031cdf5.tar.zst
coredns-c349446a23440b336f4ca21900cce4d6a031cdf5.zip
Cleanup ParseHostOrFile (#2100)
Create plugin/pkg/transport that holds the transport related functions. This needed to be a new pkg to prevent cyclic import errors. This cleans up a bunch of duplicated code in core/dnsserver that also tried to parse a transport (now all done in transport.Parse). Signed-off-by: Miek Gieben <miek@miek.nl>
Diffstat (limited to 'plugin/normalize.go')
-rw-r--r--plugin/normalize.go26
1 files changed, 4 insertions, 22 deletions
diff --git a/plugin/normalize.go b/plugin/normalize.go
index e44e55385..e38d5fa08 100644
--- a/plugin/normalize.go
+++ b/plugin/normalize.go
@@ -6,6 +6,8 @@ import (
"strconv"
"strings"
+ "github.com/coredns/coredns/plugin/pkg/transport"
+
"github.com/miekg/dns"
)
@@ -61,22 +63,10 @@ type (
// Normalize will return the host portion of host, stripping
// of any port or transport. The host will also be fully qualified and lowercased.
func (h Host) Normalize() string {
-
s := string(h)
+ _, s = transport.Parse(s)
- switch {
- case strings.HasPrefix(s, TransportTLS+"://"):
- s = s[len(TransportTLS+"://"):]
- case strings.HasPrefix(s, TransportDNS+"://"):
- s = s[len(TransportDNS+"://"):]
- case strings.HasPrefix(s, TransportGRPC+"://"):
- s = s[len(TransportGRPC+"://"):]
- case strings.HasPrefix(s, TransportHTTPS+"://"):
- s = s[len(TransportHTTPS+"://"):]
- }
-
- // The error can be ignore here, because this function is called after the corefile
- // has already been vetted.
+ // The error can be ignore here, because this function is called after the corefile has already been vetted.
host, _, _, _ := SplitHostPort(s)
return Name(host).Normalize()
}
@@ -138,11 +128,3 @@ func SplitHostPort(s string) (host, port string, ipnet *net.IPNet, err error) {
}
return host, port, n, nil
}
-
-// Duplicated from core/dnsserver/address.go !
-const (
- TransportDNS = "dns"
- TransportTLS = "tls"
- TransportGRPC = "grpc"
- TransportHTTPS = "https"
-)