aboutsummaryrefslogtreecommitdiffstats
path: root/reader
diff options
context:
space:
mode:
authorMatthew Lemon <lemon@matthewlemon.com>2019-11-01 16:48:28 +0000
committerMatthew Lemon <lemon@matthewlemon.com>2019-11-01 16:48:28 +0000
commit060508970a81bbc047f8aea975a5ce1744fb0046 (patch)
tree7fc27643db0588079ebcd238238d6144ece6d439 /reader
parent03073b44eaa801afc2faad7175669c2ee377838d (diff)
removed the pointer
Diffstat (limited to 'reader')
-rw-r--r--reader/reader.go10
-rw-r--r--reader/reader_test.go17
2 files changed, 13 insertions, 14 deletions
diff --git a/reader/reader.go b/reader/reader.go
index 33e1773..e9eabac 100644
--- a/reader/reader.go
+++ b/reader/reader.go
@@ -32,12 +32,12 @@ func Keylens(dml DatamapLine) (int, int) {
return len(dml.Key), len(dml.Sheet)
}
-//ReadDML returns a pointer to a slice of DatamapLine structs
-func ReadDML(path string) (*[]DatamapLine, error) {
+//ReadDML returns a slice of DatamapLine structs
+func ReadDML(path string) ([]DatamapLine, error) {
var s []DatamapLine
data, err := ioutil.ReadFile(path)
if err != nil {
- return &s, errors.New("Cannot find file")
+ return s, errors.New("Cannot find file")
}
r := csv.NewReader(strings.NewReader(string(data)))
for {
@@ -46,7 +46,7 @@ func ReadDML(path string) (*[]DatamapLine, error) {
break
}
if err != nil {
- return &s, errors.New("Cannot read line %s")
+ return s, errors.New("Cannot read line %s")
}
if record[0] == "cell_key" {
// this must be the header
@@ -58,7 +58,7 @@ func ReadDML(path string) (*[]DatamapLine, error) {
Cellref: strings.Trim(record[2], " ")}
s = append(s, dml)
}
- return &s, nil
+ return s, nil
}
//ReadXLSX reads an XLSX file
diff --git a/reader/reader_test.go b/reader/reader_test.go
index a7dd281..83d6a3d 100644
--- a/reader/reader_test.go
+++ b/reader/reader_test.go
@@ -6,20 +6,19 @@ import (
func TestReadDML(t *testing.T) {
d, _ := ReadDML("/home/lemon/Documents/datamaps/input/datamap.csv")
- dmlData := *d
// Test Key values
- if dmlData[0].Key != "Project/Programme Name" {
- t.Errorf("dmlData[0].Key = %s; want Project/Programme Name", dmlData[0].Key)
+ if d[0].Key != "Project/Programme Name" {
+ t.Errorf("d[0].Key = %s; want Project/Programme Name", d[0].Key)
}
- if dmlData[1].Key != "Department" {
- t.Errorf("dmlData[1].Key = %s; want Department (without a space)", dmlData[1].Key)
+ if d[1].Key != "Department" {
+ t.Errorf("d[1].Key = %s; want Department (without a space)", d[1].Key)
}
- if dmlData[2].Key != "Delivery Body" {
- t.Errorf("dmlData[2].Key = %s; want Delivery Body (without a space)", dmlData[2].Key)
+ if d[2].Key != "Delivery Body" {
+ t.Errorf("d[2].Key = %s; want Delivery Body (without a space)", d[2].Key)
}
// Test Sheet values
- if dmlData[0].Sheet != "Introduction" {
- t.Errorf("dmlData[0].Sheet = %s; want Introduction", dmlData[0].Key)
+ if d[0].Sheet != "Introduction" {
+ t.Errorf("d[0].Sheet = %s; want Introduction", d[0].Key)
}
}