From 356322bc94cde05139ecfff30ddc83dadab528f9 Mon Sep 17 00:00:00 2001 From: Alejandro Mery Date: Thu, 26 Oct 2023 18:34:42 +0000 Subject: [PATCH] dns/show: introduce writeRecords() helper to print a whole []libdns.Record Signed-off-by: Alejandro Mery --- pkg/dns/show.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pkg/dns/show.go b/pkg/dns/show.go index c29a3f0..d133a2c 100644 --- a/pkg/dns/show.go +++ b/pkg/dns/show.go @@ -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 }