diff --git a/internal/querylog/csv.go b/internal/querylog/csv.go index d985a0ac..ccd026ce 100644 --- a/internal/querylog/csv.go +++ b/internal/querylog/csv.go @@ -9,9 +9,11 @@ import ( "github.com/miekg/dns" ) +// csvRow is an alias type for csv rows. +type csvRow = [18]string + // csvHeaderRow is a slice of strings with column names for CSV header row. -// This slice should correspond with [logEntry.toCSV] func. -var csvHeaderRow = []string{ +var csvHeaderRow = csvRow{ "ans_dnssec", "ans_rcode", "ans_type", @@ -34,7 +36,7 @@ var csvHeaderRow = []string{ // toCSV returns a slice of strings with entry fields according to the // csvHeaderRow slice. -func (e *logEntry) toCSV() (out []string) { +func (e *logEntry) toCSV() (out csvRow) { var filterID, filterRule string if e.Result.IsFiltered && len(e.Result.Rules) > 0 { @@ -45,7 +47,7 @@ func (e *logEntry) toCSV() (out []string) { aData := ansData(e) - return []string{ + return csvRow{ strconv.FormatBool(e.AuthenticatedData), aData.rCode, aData.typ, diff --git a/internal/querylog/http.go b/internal/querylog/http.go index e3d9a19a..0c2172f8 100644 --- a/internal/querylog/http.go +++ b/internal/querylog/http.go @@ -125,7 +125,7 @@ func (l *queryLog) handleQueryLogExport(w http.ResponseWriter, r *http.Request) csvWriter := csv.NewWriter(w) // Write header. - if err = csvWriter.Write(csvHeaderRow); err != nil { + if err = csvWriter.Write(csvHeaderRow[:]); err != nil { http.Error(w, "writing csv header", http.StatusInternalServerError) return @@ -148,7 +148,8 @@ func (l *queryLog) handleQueryLogExport(w http.ResponseWriter, r *http.Request) params.offset += params.limit for _, entry := range entries { - if err = csvWriter.Write(entry.toCSV()); err != nil { + row := entry.toCSV() + if err = csvWriter.Write(row[:]); err != nil { // TODO(a.garipov): Set Trailer X-Error header. log.Error("%s %s %s: %s", r.Method, r.Host, r.URL, "writing csv record")