dns: introduce AddrRecord{} to abstract A/AAAA entries
Signed-off-by: Alejandro Mery <amery@jpi.io>
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
// Package dns manages DNS entries for the cluster
|
||||
package dns
|
||||
@@ -0,0 +1,38 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user