Files
jpictl/pkg/dns/record.go
T
2023-09-11 23:29:56 +00:00

39 lines
706 B
Go

package dns
import (
"net/netip"
"sort"
"time"
"darvaza.org/core"
"github.com/libdns/libdns"
)
// AddrRecord represents an A or AAAA record
type AddrRecord struct {
Name string
Addr []netip.Addr
}
// Sort sorts the addresses of the record
func (rr *AddrRecord) Sort() {
sort.Slice(rr.Addr, func(i, j int) bool {
return rr.Addr[i].Less(rr.Addr[j])
})
}
// Export converts the record into libdns.Record
func (rr *AddrRecord) Export() []libdns.Record {
out := make([]libdns.Record, len(rr.Addr))
for i, addr := range rr.Addr {
out[i] = libdns.Record{
Name: rr.Name,
TTL: time.Second * 1,
Type: core.IIf(addr.Is6(), "AAAA", "A"),
Value: addr.String(),
}
}
return out
}