Use dns.IsSubDomain (#112)

For the match function use the proper thing from go dns. Fix all
callers and tests to use this.

Fixes: #107
This commit is contained in:
Miek Gieben 2016-04-12 22:34:44 +01:00
parent 842953f179
commit 25cf16af0e
8 changed files with 22 additions and 22 deletions

View file

@ -1,21 +1,16 @@
package middleware
import (
"strings"
"github.com/miekg/dns"
)
import "github.com/miekg/dns"
type Zones []string
// Matches checks to see if other matches p. The match will return the most
// specific zones that matches other. The empty string signals a not found
// condition.
// Matches checks is qname is a subdomain of any of the zones in z. The match
// will return the most specific zones that matches other. The empty string
// signals a not found condition.
func (z Zones) Matches(qname string) string {
zone := ""
// TODO(miek): use IsSubDomain here?
for _, zname := range z {
if strings.HasSuffix(qname, zname) {
if dns.IsSubDomain(zname, qname) {
if len(zname) > len(zone) {
zone = zname
}