diff options
author | Mike Crute <mike@crute.us> | 2020-01-04 00:28:25 +0000 |
---|---|---|
committer | Mike Crute <mike@crute.us> | 2020-01-04 00:28:25 +0000 |
commit | b4214b63d7c73cb0fec55b4e678a98327a159d48 (patch) | |
tree | bb5b160d62b25f483151958f498aac81f51898db /bind | |
parent | 1a33a24e60ef985db446deb46b193ab57781ea0e (diff) | |
download | go_ddns_manager-b4214b63d7c73cb0fec55b4e678a98327a159d48.tar.bz2 go_ddns_manager-b4214b63d7c73cb0fec55b4e678a98327a159d48.tar.xz go_ddns_manager-b4214b63d7c73cb0fec55b4e678a98327a159d48.zip |
Refactor out of main a bit
Diffstat (limited to 'bind')
-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 | } |