Documentation ¶
Overview ¶
Package csvdec provides a generic CSV decoder. Wraps the encoding/csv package with a decoder that can populate structs and slices.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Decoder ¶
type Decoder struct { *csv.Reader SkipCols uint // How many columns to skip from the beginning of each line. }
A Decoder reads CSV lines and converts them to data objects. Embeds a csv.Reader, so it can be used the same way.
func NewDecoder ¶
NewDecoder returns a new decoder that reads from r. skipRows and skipCols indicate how many of the first rows and columns should be ignored.
func (*Decoder) Decode ¶
Decode reads the next CSV line and populates the given object with parsed values. Accepted input types are struct pointers and slice pointers, as explained below.
Struct pointer: all fields must be exported and of type int*, uint* float*, string or bool. Fields will be populated by order of appearance. Too few values in the CSV line will result in an error. Excess values in the CSV line will be ignored. The struct's last field may be a slice, in which case all the remaining values will be parsed for that slice's type, according to the restrictions below.
Slice pointer of type int*, uint*, float*, string: the pointer will be populated with a slice of parsed values, according to the length of the CSV line.
Any other type will cause a panic.