diff options
Diffstat (limited to 'bind/config.go')
-rw-r--r-- | bind/config.go | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/bind/config.go b/bind/config.go index 584b1ee..42b97cf 100644 --- a/bind/config.go +++ b/bind/config.go | |||
@@ -54,6 +54,25 @@ func (c *BINDConfig) Zone(view, name string) *Zone { | |||
54 | return z | 54 | return z |
55 | } | 55 | } |
56 | 56 | ||
57 | // Find the closest zone that we manage by striping dotted components off the | ||
58 | // front of the domain until one matches. If there is a match return the zone | ||
59 | // that matched and any prefix components, if any, as a dotted string. If none | ||
60 | // match then return nil. | ||
61 | func (c *BINDConfig) FindClosestZone(zoneIn, view string) (*Zone, string) { | ||
62 | suffix := "" | ||
63 | prefix := []string{} | ||
64 | |||
65 | zc := strings.Split(zoneIn, ".") | ||
66 | for i := 0; i <= len(zc)-2; i++ { | ||
67 | prefix, suffix = zc[:i], strings.Join(zc[i:], ".") | ||
68 | if zone := c.Zone(view, suffix); zone != nil { | ||
69 | return zone, strings.Join(prefix, ".") | ||
70 | } | ||
71 | } | ||
72 | |||
73 | return nil, "" | ||
74 | } | ||
75 | |||
57 | func (c *BINDConfig) AddKey(k *Key) { | 76 | func (c *BINDConfig) AddKey(k *Key) { |
58 | c.keys[k.Name] = k | 77 | c.keys[k.Name] = k |
59 | } | 78 | } |