aboutsummaryrefslogtreecommitdiff
path: root/middleware/zone.go
blob: 13255411c986f73b090b17c30dd5d2ca72565e86 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package middleware

import (
	"strings"

	"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.
func (z Zones) Matches(qname string) string {
	zone := ""
	// TODO(miek): use IsSubDomain here?
	for _, zname := range z {
		println(zname, qname)
		if strings.HasSuffix(qname, zname) {
			if len(zname) > len(zone) {
				zone = zname
			}
		}
	}
	return zone
}

// Fully qualify all zones in z
func (z Zones) FullyQualify() {
	for i, _ := range z {
		z[i] = dns.Fqdn(z[i])
	}

}