2016-03-18 20:57:35 +00:00
|
|
|
package middleware
|
|
|
|
|
|
2016-04-12 22:34:44 +01:00
|
|
|
import "github.com/miekg/dns"
|
2016-03-18 20:57:35 +00:00
|
|
|
|
|
|
|
|
type Zones []string
|
|
|
|
|
|
2016-04-12 22:34:44 +01:00
|
|
|
// 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.
|
2016-03-18 20:57:35 +00:00
|
|
|
func (z Zones) Matches(qname string) string {
|
|
|
|
|
zone := ""
|
|
|
|
|
for _, zname := range z {
|
2016-04-12 22:34:44 +01:00
|
|
|
if dns.IsSubDomain(zname, qname) {
|
2016-03-18 20:57:35 +00:00
|
|
|
if len(zname) > len(zone) {
|
|
|
|
|
zone = zname
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return zone
|
|
|
|
|
}
|
2016-03-22 22:44:50 +00:00
|
|
|
|
2016-04-03 07:44:28 +01:00
|
|
|
// FullyQualify fully qualifies all zones in z.
|
2016-03-22 22:44:50 +00:00
|
|
|
func (z Zones) FullyQualify() {
|
|
|
|
|
for i, _ := range z {
|
|
|
|
|
z[i] = dns.Fqdn(z[i])
|
|
|
|
|
}
|
|
|
|
|
}
|