summaryrefslogtreecommitdiff
path: root/dns/types.go
blob: aa5112b8bfe922812380c7d2baf65ae5c0bff54a (plain)
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
35
package dns

import (
	"fmt"
	_ "net"

	"code.crute.me/mcrute/go_ddns_manager/bind"
	"github.com/miekg/dns"
)

//go:generate go run ../generate_dns_types.go

func makeHeader(name string, zone *bind.Zone, t uint16, ttl int) dns.RR_Header {
	return dns.RR_Header{
		Name:   fmt.Sprintf("%s.%s", name, zone.Name),
		Rrtype: t,
		Class:  dns.ClassINET,
		Ttl:    uint32(ttl),
	}
}

func toRRSet(z *bind.Zone, rr ...RR) []dns.RR {
	o := []dns.RR{}
	for _, v := range rr {
		o = append(o, v.ToDNS(z))
	}
	return o
}

type RR interface {
	ToDNS(*bind.Zone) dns.RR
	FromDNS(rr dns.RR) error
	MarshalJSON() ([]byte, error)
	UnmarshalJSON(data []byte) error
}