-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprinter_text.go
49 lines (41 loc) · 1.09 KB
/
printer_text.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package main
import (
"fmt"
"github.com/fatih/color"
)
type TextResultPrinter struct {
Identical bool
}
func (printer TextResultPrinter) Print(results []DnsResult) {
diffCount := 0
for _, result := range results {
if !printer.Identical && result.Identical {
continue
}
printer.printResult(result)
diffCount++
}
if !printer.Identical && diffCount == 0 {
greenColor := color.New(color.FgGreen)
_, _ = greenColor.Println("All records are identical")
}
}
func (printer TextResultPrinter) printResult(result DnsResult) {
headingColor := color.New(color.FgGreen)
if !result.Identical {
headingColor = color.New(color.FgRed)
_, _ = headingColor.Println("DIFFERENT")
}
_, _ = headingColor.Println(fmt.Sprintf("%s -> %s", result.Type, result.Host))
recordColor := color.New(color.FgYellow)
nameserverColor := color.New(color.FgCyan)
for _, response := range result.Responses {
_, _ = recordColor.Print(response.Value)
if response.Value == "" {
_, _ = recordColor.Print("EMPTY")
}
fmt.Print(" <==> ")
_, _ = nameserverColor.Println(response.Resolver)
}
fmt.Println("---")
}