dns/show: introduce writeRecords() helper

to print a whole []libdns.Record

Signed-off-by: Alejandro Mery <amery@jpi.io>
This commit is contained in:
2023-10-26 18:34:42 +00:00
parent 7dac96f474
commit 356322bc94
+7 -3
View File
@@ -14,20 +14,24 @@ import (
// Show shows current DNS entries
func (mgr *Manager) Show(ctx context.Context, names ...string) error {
var buf bytes.Buffer
recs, err := mgr.GetRecords(ctx, names...)
if err != nil {
return core.Wrap(err, "GetRecords")
}
return writeRecords(recs, os.Stdout)
}
func writeRecords(recs []libdns.Record, w io.Writer) error {
var buf bytes.Buffer
for _, rr := range recs {
_ = fmtRecord(&buf, rr)
_, _ = buf.WriteRune('\n')
}
_, _ = fmt.Fprintf(&buf, "; %v records\n", len(recs))
_, err = buf.WriteTo(os.Stdout)
_, err := buf.WriteTo(w)
return err
}