Skip to content

Commit 3de5957

Browse files
committed
Suggested Changes
1 parent 361cd23 commit 3de5957

File tree

1 file changed

+34
-31
lines changed

1 file changed

+34
-31
lines changed

internal/analyse/analyse.go

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ import (
1616
type NoteLevel string
1717

1818
const (
19-
NoteLevelWarn NoteLevel = "warn"
20-
NoteLevelError NoteLevel = "error"
19+
NoteLevelWarn NoteLevel = "warn"
20+
NoteLevelError NoteLevel = "error"
21+
fingerprintHeader = "SHA-256 Fingerprint"
22+
commentsHeader = "Comments"
2123
)
2224

2325
type Note struct {
@@ -53,45 +55,46 @@ func downloadMozillaRemovedCACertsList() ([]removedCertificate, error) {
5355
return nil, err
5456
}
5557
csvReader := csv.NewReader(resp.Body)
56-
csvLines, err := csvReader.ReadAll()
58+
// Read the header first
59+
headers, err := csvReader.Read()
5760
if err != nil {
5861
return nil, err
5962
}
6063

61-
removedCerts := make([]removedCertificate, len(csvLines))
62-
for i, csvLine := range csvLines {
63-
// Skip the header row
64-
if i == 0 {
65-
continue
64+
// Find column indices by their names from the header
65+
fingerprint := -1
66+
comments := -1
67+
for idx, header := range headers {
68+
switch header {
69+
case fingerprintHeader:
70+
fingerprint = idx
71+
case commentsHeader:
72+
comments = idx
6673
}
74+
}
6775

68-
// Find column indices by their names from the header
69-
var fingerprint, comments int
70-
if i == 1 {
71-
fingerprint = -1
72-
comments = -1
73-
for idx, header := range csvLines[0] {
74-
switch header {
75-
case "SHA-256 Fingerprint":
76-
fingerprint = idx
77-
case "Comments":
78-
comments = idx
79-
}
80-
}
76+
if fingerprint == -1 {
77+
return nil, fmt.Errorf("required column 'SHA-256 Fingerprint' not found in CSV header")
78+
}
79+
if comments == -1 {
80+
return nil, fmt.Errorf("required column 'Comments' not found in CSV header")
81+
}
8182

82-
if fingerprint == -1 {
83-
return nil, fmt.Errorf("required column 'SHA-256 Fingerprint' not found in CSV header")
84-
}
85-
if comments == -1 {
86-
return nil, fmt.Errorf("required column 'Comments' not found in CSV header")
87-
}
83+
// Now process each line individually instead of loading everything into memory
84+
var removedCerts []removedCertificate
85+
for {
86+
record, err := csvReader.Read()
87+
if err != nil {
88+
break // End of file or other error
8889
}
8990

90-
removedCerts[i-1] = removedCertificate{
91-
Fingerprint: csvLine[fingerprint],
92-
Comments: csvLine[comments],
93-
}
91+
removedCerts = append(removedCerts, removedCertificate{
92+
Fingerprint: record[fingerprint],
93+
Comments: record[comments],
94+
})
9495
}
96+
97+
// All CSV processing is done in the loop above, we already have the removedCerts slice
9598
return removedCerts, nil
9699
}
97100

0 commit comments

Comments
 (0)