valuesFromCSV reads the CSV-formatted reader r and returns the set of values in the 0-based column index.. Note: rows not having enough columns to extract the colIdx-th column are simply discarded.
(r io.Reader, colIdx int)
| 151 | // Note: rows not having enough columns to extract the colIdx-th column are |
| 152 | // simply discarded. |
| 153 | func valuesFromCSV(r io.Reader, colIdx int) (map[string]struct{}, error) { |
| 154 | csvReader := csv.NewReader(r) |
| 155 | csvReader.ReuseRecord = true |
| 156 | // -1 to not raise an error if rows do not all have the same number of fields. |
| 157 | csvReader.FieldsPerRecord = -1 |
| 158 | |
| 159 | values := make(map[string]struct{}) |
| 160 | for { |
| 161 | row, err := csvReader.Read() |
| 162 | if err != nil { |
| 163 | if err == io.EOF { |
| 164 | err = nil |
| 165 | } |
| 166 | return values, err |
| 167 | } |
| 168 | if colIdx >= len(row) { |
| 169 | continue // omit row |
| 170 | } |
| 171 | values[row[colIdx]] = struct{}{} |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | func (f *ExternalMatch) processURL(u string) (map[string]struct{}, error) { |
| 176 | parsed, err := url.Parse(u) |