From a4fc0d43515d03de3fa8c9d7460671a04c905037 Mon Sep 17 00:00:00 2001 From: Harry Stebbins <147427727+harry-stebbins-dailypay@users.noreply.github.com> Date: Tue, 3 Sep 2024 16:55:22 -0400 Subject: [PATCH] fix: return nil when HeaderTable.Get does not find a corresponding header (#36) --- datatable.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/datatable.go b/datatable.go index c96fb60..c590ec3 100644 --- a/datatable.go +++ b/datatable.go @@ -91,9 +91,14 @@ type HeaderTable struct { } // Get returns the cell at the provided row offset (skipping the header row) -// and column name (as indicated in the header). +// and column name (as indicated in the header). If the column name is not +// found, nil is returned. func (h *HeaderTable) Get(row int, col string) *Cell { - return h.DataTable.Cell(row+1, h.headers[col]) + if v, ok := h.headers[col]; !ok { + return nil + } else { + return h.DataTable.Cell(row+1, v) + } } // NumRows returns the number of rows in the table (excluding the header row).