Document every exported symbol and how callers use the library.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-09-29 19:25:43 +02:00
co-authored by Cursor
parent c2cdd85ef1
commit 1bb7abd96b
10 changed files with 842 additions and 81 deletions
+26 -12
View File
@@ -8,7 +8,9 @@ import (
"github.com/miekg/dns"
)
// Record is a single resource record with presentation-format rdata.
// Record is one resource record.
// Owner is a trailing-dot FQDN. Class and Type are presentation names such as IN and A.
// RData is the presentation-format rdata, without the owner, TTL, class, or type.
type Record struct {
Owner string
Class string
@@ -25,14 +27,15 @@ type RRSet struct {
Records []Record
}
// Zone is a complete in-memory zone from AXFR (or assembled records).
// Zone is an in-memory zone: origin, SOA serial, and a flat record list.
// AXFR returns one. Callers can also assemble a Zone and call RRSets.
type Zone struct {
Origin string
Serial uint32
Records []Record
}
// RRSets groups Zone records by owner/class/type, preserving first-seen order.
// RRSets groups Zone records by owner, class, and type, in first-seen order.
func (z Zone) RRSets() []RRSet {
type key struct{ owner, class, typ string }
order := make([]key, 0)
@@ -51,7 +54,9 @@ func (z Zone) RRSets() []RRSet {
return out
}
// A builds an IPv4 address record.
// A builds an IN A record.
// It returns an error when ip is not IPv4, or when owner is empty or not ASCII.
// Owner is stored as a trailing-dot FQDN.
func A(owner string, ttl uint32, ip net.IP) (Record, error) {
v4 := ip.To4()
if v4 == nil {
@@ -60,7 +65,9 @@ func A(owner string, ttl uint32, ip net.IP) (Record, error) {
return fromRR(&dns.A{Hdr: rrHeader(owner, dns.TypeA, ttl), A: v4})
}
// AAAA builds an IPv6 address record.
// AAAA builds an IN AAAA record.
// It returns an error when ip is missing, is IPv4, or when owner is empty or not ASCII.
// Owner is stored as a trailing-dot FQDN.
func AAAA(owner string, ttl uint32, ip net.IP) (Record, error) {
if ip == nil || ip.To16() == nil || ip.To4() != nil {
return Record{}, fmt.Errorf("AAAA record requires an IPv6 address")
@@ -68,7 +75,8 @@ func AAAA(owner string, ttl uint32, ip net.IP) (Record, error) {
return fromRR(&dns.AAAA{Hdr: rrHeader(owner, dns.TypeAAAA, ttl), AAAA: ip.To16()})
}
// MX builds a mail-exchanger record.
// MX builds an IN MX record for preference pref and exchanger target.
// It returns an error when owner or target is empty or not ASCII.
func MX(owner string, ttl uint32, pref uint16, target string) (Record, error) {
name, err := fqdnASCII(target)
if err != nil {
@@ -77,12 +85,14 @@ func MX(owner string, ttl uint32, pref uint16, target string) (Record, error) {
return fromRR(&dns.MX{Hdr: rrHeader(owner, dns.TypeMX, ttl), Preference: pref, Mx: name})
}
// TXT builds a text record.
// TXT builds an IN TXT record whose rdata is text.
// It returns an error when owner is empty or not ASCII.
func TXT(owner string, ttl uint32, text string) (Record, error) {
return fromRR(&dns.TXT{Hdr: rrHeader(owner, dns.TypeTXT, ttl), Txt: []string{text}})
}
// CNAME builds a canonical-name record.
// CNAME builds an IN CNAME record pointing at target.
// It returns an error when owner or target is empty or not ASCII.
func CNAME(owner string, ttl uint32, target string) (Record, error) {
name, err := fqdnASCII(target)
if err != nil {
@@ -91,7 +101,8 @@ func CNAME(owner string, ttl uint32, target string) (Record, error) {
return fromRR(&dns.CNAME{Hdr: rrHeader(owner, dns.TypeCNAME, ttl), Target: name})
}
// NS builds a nameserver record.
// NS builds an IN NS record pointing at target.
// It returns an error when owner or target is empty or not ASCII.
func NS(owner string, ttl uint32, target string) (Record, error) {
name, err := fqdnASCII(target)
if err != nil {
@@ -100,7 +111,8 @@ func NS(owner string, ttl uint32, target string) (Record, error) {
return fromRR(&dns.NS{Hdr: rrHeader(owner, dns.TypeNS, ttl), Ns: name})
}
// SRV builds a service locator record.
// SRV builds an IN SRV record.
// It returns an error when owner or target is empty or not ASCII.
func SRV(owner string, ttl uint32, prio, weight, port uint16, target string) (Record, error) {
name, err := fqdnASCII(target)
if err != nil {
@@ -115,7 +127,8 @@ func SRV(owner string, ttl uint32, prio, weight, port uint16, target string) (Re
})
}
// PTR builds a pointer record.
// PTR builds an IN PTR record pointing at target.
// It returns an error when owner or target is empty or not ASCII.
func PTR(owner string, ttl uint32, target string) (Record, error) {
name, err := fqdnASCII(target)
if err != nil {
@@ -124,7 +137,8 @@ func PTR(owner string, ttl uint32, target string) (Record, error) {
return fromRR(&dns.PTR{Hdr: rrHeader(owner, dns.TypePTR, ttl), Ptr: name})
}
// CAA builds a certification-authority authorization record (RFC 8659).
// CAA builds an IN CAA record (RFC 8659) with flag, tag, and value.
// It returns an error when owner is empty or not ASCII.
func CAA(owner string, ttl uint32, flag uint8, tag, value string) (Record, error) {
return fromRR(&dns.CAA{
Hdr: rrHeader(owner, dns.TypeCAA, ttl),