summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Crute <mike@crute.us>2023-08-22 08:06:32 -0700
committerMike Crute <mike@crute.us>2023-08-22 08:06:41 -0700
commit6a36dda54e596262d9079bc303e094453e9b6558 (patch)
treeaf531b824298c9b9da5011f14606a243738a3914
parentabee373da2adedf9785b422f274ca82fcbe9210e (diff)
downloadgo_ddns_manager-6a36dda54e596262d9079bc303e094453e9b6558.tar.bz2
go_ddns_manager-6a36dda54e596262d9079bc303e094453e9b6558.tar.xz
go_ddns_manager-6a36dda54e596262d9079bc303e094453e9b6558.zip
Generated types rely on interface
-rw-r--r--bind/config.go4
-rw-r--r--dns/types.go13
-rw-r--r--generate_dns_types.go4
3 files changed, 13 insertions, 8 deletions
diff --git a/bind/config.go b/bind/config.go
index 1d4a81a..62c1324 100644
--- a/bind/config.go
+++ b/bind/config.go
@@ -119,6 +119,10 @@ type Zone struct {
119 config *BINDConfig 119 config *BINDConfig
120} 120}
121 121
122func (z *Zone) ZoneName() string {
123 return z.Name
124}
125
122func (z *Zone) AddKey(key string) { 126func (z *Zone) AddKey(key string) {
123 z.keys = append(z.keys, key) 127 z.keys = append(z.keys, key)
124} 128}
diff --git a/dns/types.go b/dns/types.go
index aa5112b..4a02d2c 100644
--- a/dns/types.go
+++ b/dns/types.go
@@ -4,22 +4,25 @@ import (
4 "fmt" 4 "fmt"
5 _ "net" 5 _ "net"
6 6
7 "code.crute.me/mcrute/go_ddns_manager/bind"
8 "github.com/miekg/dns" 7 "github.com/miekg/dns"
9) 8)
10 9
11//go:generate go run ../generate_dns_types.go 10//go:generate go run ../generate_dns_types.go
12 11
13func makeHeader(name string, zone *bind.Zone, t uint16, ttl int) dns.RR_Header { 12type NamedZone interface {
13 ZoneName() string
14}
15
16func makeHeader(name string, zone NamedZone, t uint16, ttl int) dns.RR_Header {
14 return dns.RR_Header{ 17 return dns.RR_Header{
15 Name: fmt.Sprintf("%s.%s", name, zone.Name), 18 Name: fmt.Sprintf("%s.%s", name, zone.ZoneName()),
16 Rrtype: t, 19 Rrtype: t,
17 Class: dns.ClassINET, 20 Class: dns.ClassINET,
18 Ttl: uint32(ttl), 21 Ttl: uint32(ttl),
19 } 22 }
20} 23}
21 24
22func toRRSet(z *bind.Zone, rr ...RR) []dns.RR { 25func toRRSet(z NamedZone, rr ...RR) []dns.RR {
23 o := []dns.RR{} 26 o := []dns.RR{}
24 for _, v := range rr { 27 for _, v := range rr {
25 o = append(o, v.ToDNS(z)) 28 o = append(o, v.ToDNS(z))
@@ -28,7 +31,7 @@ func toRRSet(z *bind.Zone, rr ...RR) []dns.RR {
28} 31}
29 32
30type RR interface { 33type RR interface {
31 ToDNS(*bind.Zone) dns.RR 34 ToDNS(NamedZone) dns.RR
32 FromDNS(rr dns.RR) error 35 FromDNS(rr dns.RR) error
33 MarshalJSON() ([]byte, error) 36 MarshalJSON() ([]byte, error)
34 UnmarshalJSON(data []byte) error 37 UnmarshalJSON(data []byte) error
diff --git a/generate_dns_types.go b/generate_dns_types.go
index 4e2aade..4e90693 100644
--- a/generate_dns_types.go
+++ b/generate_dns_types.go
@@ -30,8 +30,6 @@ import (
30 "net" 30 "net"
31 31
32 "github.com/miekg/dns" 32 "github.com/miekg/dns"
33
34 "code.crute.me/mcrute/go_ddns_manager/bind"
35) 33)
36 34
37{{ range $name, $fields := . -}} 35{{ range $name, $fields := . -}}
@@ -43,7 +41,7 @@ type {{ $name }} struct {
43 {{ end -}} 41 {{ end -}}
44} 42}
45 43
46func (r *{{ $name }}) ToDNS(zone *bind.Zone) dns.RR { 44func (r *{{ $name }}) ToDNS(zone NamedZone) dns.RR {
47 return &dns.{{ $name }}{ 45 return &dns.{{ $name }}{
48 Hdr: makeHeader(r.Name, zone, dns.Type{{ $name }}, r.Ttl), 46 Hdr: makeHeader(r.Name, zone, dns.Type{{ $name }}, r.Ttl),
49 {{ range $fields -}} 47 {{ range $fields -}}