|
1 | 1 | // csvdecoder is a tool for parsing and deserializing CSV values into Go objects. |
2 | 2 | // It follows the same usage pattern as the Rows scanning using database/sql package. |
3 | 3 | // It relies on encoding/csv for the actual csv parsing. |
4 | | - |
| 4 | +// |
5 | 5 | // csvdecoder allows to iterate through the CSV records (using 'Next') |
6 | 6 | // and scan the fields into target variables or fields of variables (using 'Scan'). |
7 | | -// The 'Next' and 'Scan' methods are not thread-safe and are not expected to be called concurrently. |
8 | | - |
| 7 | +// The methods 'Next' and 'Scan' are not thread-safe and are not expected to be called concurrently. |
| 8 | +// |
9 | 9 | // csvdecoder supports converting CSV fields into any of the following types: |
10 | | -// - `*string` |
11 | | -// - `*int`, `*int8`, `*int16`, `*int32`, `*int64` |
12 | | -// - `*uint`, `*uint8`, `*uint16`, `*uint32`, `*uint64` |
13 | | -// - `*bool` |
14 | | -// - `*float32`, `*float64` |
15 | | -// - a slice of values. Note that the CSV field must be a valid JSON array. If not a JSON array, a custom decoder implementing the `csvdecoder.Interface` interface must be implemented. |
16 | | -// - an array of values. Note that the CSV field must be a valid JSON array. If not a JSON array, a custom decoder implementing the `csvdecoder.Interface` interface must be implemented. |
17 | | -// - a pointer to any type implementing the `csvdecoder.Interface` interface |
18 | | - |
| 10 | +// *string |
| 11 | +// *int, *int8, *int16, *int32, *int64 |
| 12 | +// *uint, *uint8, *uint16, *uint32, *uint64 |
| 13 | +// *bool |
| 14 | +// *float32, *float64 |
| 15 | +// a slice of values. Note that the CSV field must be a valid JSON array. If not a JSON array, a custom decoder implementing the csvdecoder.Interface interface must be implemented. |
| 16 | +// an array of values. Note that the CSV field must be a valid JSON array. If not a JSON array, a custom decoder implementing the csvdecoder.Interface interface must be implemented. |
| 17 | +// a pointer to any type implementing the csvdecoder.Interface interface |
| 18 | +// |
19 | 19 | // csvdecoder uses the same terminology as package encoding/csv: |
20 | 20 | // A csv file contains zero or more records. Each record contains one or more |
21 | 21 | // fields separated by the fields separator (the "comma"). The fields separator character |
22 | 22 | // can be configured to be another character than comma. |
23 | 23 | // Each record is separated by the newline character. The final record may |
24 | 24 | // optionally be followed by a newline character. |
25 | | - |
| 25 | +// |
26 | 26 | // The behavior of the decoder can be configured by passing one of following options when creating the decoder: |
27 | | -// - Comma: the character that separates values. The default value is comma. |
28 | | -// - IgnoreHeaders: if set to true, the first line will be ignored. This is useful when the CSV file contains a header line. |
29 | | -// - IgnoreUnmatchingFields: if set to true, the number of fields and scan targets are allowed to be different. By default, if they don't match exactly it will cause an error. |
30 | | - |
| 27 | +// Comma: the character that separates values. The default value is comma. |
| 28 | +// IgnoreHeaders: if set to true, the first line will be ignored. This is useful when the CSV file contains a header line. |
| 29 | +// IgnoreUnmatchingFields: if set to true, the number of fields and scan targets are allowed to be different. By default, if they don't match exactly it will cause an error. |
| 30 | +// |
31 | 31 | // See README.md for more info. |
32 | 32 | package csvdecoder |
0 commit comments