Skip to content

Commit

Permalink
refactor: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
natesales committed Sep 7, 2023
1 parent d16c5c0 commit 4f1f371
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 18 deletions.
3 changes: 1 addition & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,8 +416,7 @@ All long form (--) flags can be toggled with the dig-standard +[no]flag notation
rrTypes[dns.StringToType["NS"]] = true
} else {
for _, defaultRRType := range opts.DefaultRRTypes {
rrType, _ := dns.StringToType[defaultRRType]
rrTypes[rrType] = true
rrTypes[dns.StringToType[defaultRRType]] = true
}
}
}
Expand Down
11 changes: 4 additions & 7 deletions output.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func printPrettyRR(a dns.RR, doWhois bool, out io.Writer) {

ttl := fmt.Sprintf("%d", a.Header().Ttl)
if opts.PrettyTTLs {
ttl = fmt.Sprintf("%s", time.Duration(a.Header().Ttl)*time.Second)
ttl = (time.Duration(a.Header().Ttl) * time.Second).String()
}

if doWhois && (a.Header().Rrtype == dns.TypeA || a.Header().Rrtype == dns.TypeAAAA) {
Expand Down Expand Up @@ -115,11 +115,8 @@ func prettyPrintNSID(opt []*dns.Msg, out io.Writer) {
}

func display(replies []*dns.Msg, server string, queryTime time.Duration, out io.Writer) error {
switch opts.Format {
case "pretty":
if opts.NSID {
prettyPrintNSID(replies, out)
}
if opts.NSID && opts.Format == "pretty" {
prettyPrintNSID(replies, out)
}

for i, reply := range replies {
Expand Down Expand Up @@ -198,7 +195,7 @@ func display(replies []*dns.Msg, server string, queryTime time.Duration, out io.

mustWritef(out, "Opcode: %s Status: %s ID %s: Flags: %s (%s Query %s Ans %s Auth %s Add)\n",
color("magenta", dns.OpcodeToString[reply.MsgHdr.Opcode]),
color("teal", fmt.Sprintf("%s", dns.RcodeToString[reply.MsgHdr.Rcode])),
color("teal", dns.RcodeToString[reply.MsgHdr.Rcode]),
color("green", fmt.Sprintf("%d", reply.MsgHdr.Id)),
color("purple", flags),
color("purple", fmt.Sprintf("%d", len(reply.Question))),
Expand Down
16 changes: 11 additions & 5 deletions transport/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ func TestTransportHTTPInvalidResolver(t *testing.T) {
func TestTransportHTTPServerError(t *testing.T) {
listen := ":5380"
go func() {
http.ListenAndServe(listen, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if err := http.ListenAndServe(listen, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
http.Error(w, "Server Error", http.StatusInternalServerError)
}))
})); err != nil {
t.Errorf("error starting HTTP server: %s", err)
}
}()

tp := httpTransport()
Expand All @@ -57,16 +59,20 @@ func TestTransportHTTPServerError(t *testing.T) {
func TestTransportHTTPIDMismatch(t *testing.T) {
listen := ":5381"
go func() {
http.ListenAndServe(listen, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if err := http.ListenAndServe(listen, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
msg := dns.Msg{}
msg.Id = 1
buf, err := msg.Pack()
if err != nil {
t.Errorf("error packing DNS message: %s", err)
return
}
w.Write(buf)
}))
if _, err := w.Write(buf); err != nil {
t.Errorf("error writing DNS message: %s", err)
}
})); err != nil {
t.Errorf("error starting HTTP server: %s", err)
}
}()

tp := httpTransport()
Expand Down
2 changes: 1 addition & 1 deletion transport/odoh.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func (o *ODoH) Exchange(m *dns.Msg) (*dns.Msg, error) {
if len(odohConfigs.Configs) == 0 {
return nil, errors.New("target provided no valid ODoH configs")
}
log.Debugf("[odoh] retreived %d ODoH configs", len(odohConfigs.Configs))
log.Debugf("[odoh] retrieved %d ODoH configs", len(odohConfigs.Configs))

packedDnsQuery, err := m.Pack()
if err != nil {
Expand Down
4 changes: 1 addition & 3 deletions xfr.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ func axfr(label, server string) []dns.RR {
log.Warnf("AXFR section error (%s): %s", label, env.Error)
continue
}
for _, rr := range env.RR {
rrs = append(rrs, rr)
}
rrs = append(rrs, env.RR...)
}

return rrs
Expand Down

0 comments on commit 4f1f371

Please sign in to comment.