Files
jpictl/pkg/dns/write.go
T
amery 8d1b9c4f04 WIP
Signed-off-by: Alejandro Mery <amery@jpi.io>
2023-09-12 12:49:14 +00:00

36 lines
634 B
Go

package dns
import (
"bytes"
"fmt"
"io"
"time"
"github.com/libdns/libdns"
)
// WriteTo writes the DNS data for the cluster
func (mgr *Manager) WriteTo(w io.Writer) (int64, error) {
var buf bytes.Buffer
records := mgr.genAllAddrRecords()
for i := range records {
r := &records[i]
r.Name = fmt.Sprintf("%s.%s.", r.Name, mgr.domain)
}
for _, rr1 := range records {
for _, rr2 := range rr1.Export() {
writeRecord(&buf, rr2)
}
}
return buf.WriteTo(w)
}
func writeRecord(w io.Writer, rr libdns.Record) {
_, _ = fmt.Fprintf(w, "%s\t%v\tIN\t%s\t%s\n",
rr.Name, int(rr.TTL/time.Second),
rr.Type, rr.Value)
}