MCPcopy Create free account
hub / github.com/AdRoll/baker / valuesFromCSV

Function valuesFromCSV

filter/external_match.go:153–173  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

151// Note: rows not having enough columns to extract the colIdx-th column are
152// simply discarded.
153func 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
175func (f *ExternalMatch) processURL(u string) (map[string]struct{}, error) {
176 parsed, err := url.Parse(u)

Callers 1

processURLMethod · 0.85

Calls 1

ReadMethod · 0.80

Tested by

no test coverage detected