From abef9b7f0a957811a452885bee1070e989dc2d91 Mon Sep 17 00:00:00 2001 From: Martin Polden Date: Thu, 26 Dec 2019 19:51:58 +0100 Subject: Include rcode in API responses --- http/http.go | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) (limited to 'http/http.go') diff --git a/http/http.go b/http/http.go index 98ca90d..c2c6c5c 100644 --- a/http/http.go +++ b/http/http.go @@ -26,7 +26,8 @@ type entry struct { RemoteAddr net.IP `json:"remote_addr,omitempty"` Qtype string `json:"type"` Question string `json:"question"` - Answers []string `json:"answers"` + Answers []string `json:"answers,omitempty"` + Rcode string `json:"rcode,omitempty"` } type httpError struct { @@ -99,26 +100,15 @@ func (s *Server) cacheHandler(w http.ResponseWriter, r *http.Request) (interface entries = append(entries, entry{ Time: v.CreatedAt.UTC().Format(time.RFC3339), TTL: int64(v.TTL().Truncate(time.Second).Seconds()), - Qtype: qtype(v.Qtype), - Question: v.Question, - Answers: v.Answers, + Qtype: dns.TypeToString[v.Qtype()], + Question: v.Question(), + Answers: v.Answers(), + Rcode: dns.RcodeToString[v.Rcode()], }) } return entries, nil } -func qtype(qtype uint16) string { - switch qtype { - case dns.TypeA: - return "A" - case dns.TypeAAAA: - return "AAAA" - case dns.TypeMX: - return "MX" - } - return "" -} - func (s *Server) logHandler(w http.ResponseWriter, r *http.Request) (interface{}, *httpError) { logEntries, err := s.logger.Get(100) if err != nil { @@ -132,7 +122,7 @@ func (s *Server) logHandler(w http.ResponseWriter, r *http.Request) (interface{} entries = append(entries, entry{ Time: le.Time.UTC().Format(time.RFC3339), RemoteAddr: le.RemoteAddr, - Qtype: qtype(le.Qtype), + Qtype: dns.TypeToString[le.Qtype], Question: le.Question, Answers: le.Answers, }) -- cgit v1.2.3