Skip to content

Commit

Permalink
fix: deduplicate output in pretty print mode
Browse files Browse the repository at this point in the history
Closes: #21
  • Loading branch information
natesales committed Oct 23, 2022
1 parent 2d1da48 commit 9c035b4
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,18 @@ func color(color string, args ...interface{}) string {
}
}

var existingRRs = map[string]bool{}

// printPrettyRR prints a pretty RR
func printPrettyRR(a dns.RR) {
val := strings.TrimSpace(strings.Join(strings.Split(a.String(), dns.TypeToString[a.Header().Rrtype])[1:], ""))
rrSignature := fmt.Sprintf("%s %d %s %s", a.Header().Name, a.Header().Ttl, dns.TypeToString[a.Header().Rrtype], val)
if ok := existingRRs[rrSignature]; ok {
return
} else {
existingRRs[rrSignature] = true
}

ttl := fmt.Sprintf("%d", a.Header().Ttl)
if opts.PrettyTTLs {
ttl = fmt.Sprintf("%s", time.Duration(a.Header().Ttl)*time.Second)
Expand All @@ -164,7 +174,7 @@ func printPrettyRR(a dns.RR) {
color("purple", a.Header().Name),
color("green", ttl),
color("magenta", dns.TypeToString[a.Header().Rrtype]),
strings.TrimSpace(strings.Join(strings.Split(a.String(), dns.TypeToString[a.Header().Rrtype])[1:], "")),
val,
)
}

Expand Down

0 comments on commit 9c035b4

Please sign in to comment.