dns: introduce AddrRecord{} to abstract A/AAAA entries
Signed-off-by: Alejandro Mery <amery@jpi.io>
This commit is contained in:
@@ -13,6 +13,7 @@ require (
|
||||
darvaza.org/slog/handlers/discard v0.4.5
|
||||
github.com/gofrs/uuid/v5 v5.0.0
|
||||
github.com/hack-pad/hackpadfs v0.2.1
|
||||
github.com/libdns/libdns v0.2.1
|
||||
github.com/mgechev/revive v1.3.3
|
||||
github.com/spf13/cobra v1.7.0
|
||||
golang.org/x/crypto v0.12.0
|
||||
|
||||
@@ -34,6 +34,8 @@ github.com/hack-pad/hackpadfs v0.2.1 h1:FelFhIhv26gyjujoA/yeFO+6YGlqzmc9la/6iKMI
|
||||
github.com/hack-pad/hackpadfs v0.2.1/go.mod h1:khQBuCEwGXWakkmq8ZiFUvUZz84ZkJ2KNwKvChs4OrU=
|
||||
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
|
||||
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
|
||||
github.com/libdns/libdns v0.2.1 h1:Wu59T7wSHRgtA0cfxC+n1c/e+O3upJGWytknkmFEDis=
|
||||
github.com/libdns/libdns v0.2.1/go.mod h1:yQCXzk1lEZmmCPa857bnk4TsOiqYasqpyOEeSObbb40=
|
||||
github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
|
||||
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
|
||||
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
|
||||
|
||||
@@ -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
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
// Package dns manages DNS entries for the cluster
|
||||
package dns
|
||||
Reference in New Issue
Block a user