doggo/cmd/output.go

34 lines
905 B
Go
Raw Normal View History

2020-12-12 11:57:13 +01:00
package main
2020-12-12 15:10:28 +01:00
import (
"fmt"
"strconv"
"github.com/fatih/color"
"github.com/miekg/dns"
"github.com/mr-karan/doggo/pkg/resolvers"
)
2020-12-12 11:57:13 +01:00
// Output takes a list of `dns.Answers` and based
// on the output format specified displays the information.
2020-12-12 15:10:28 +01:00
func (hub *Hub) Output(responses []resolvers.Response) {
// Create SprintXxx functions to mix strings with other non-colorized strings:
green := color.New(color.FgGreen).SprintFunc()
blue := color.New(color.FgBlue).SprintFunc()
for _, r := range responses {
var res string
for _, a := range r.Message.Answer {
switch t := a.(type) {
case *dns.A:
res = t.A.String()
}
h := a.Header()
name := green(h.Name)
qclass := dns.Class(h.Class).String()
ttl := strconv.FormatInt(int64(h.Ttl), 10) + "s"
qtype := blue(dns.Type(h.Rrtype).String())
fmt.Printf("%s \t %s \t %s \t %s \t %s\n", qtype, name, qclass, ttl, res)
}
}
}