Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Reader ¶
A Reader reads records from a CSV-encoded file.
func NewReader ¶
NewReader returns a new Reader that reads from r.
Example ¶
reader := NewReader(bytes.NewBuffer(nil)) fmt.Println(string(reader.Reader.Comma))
Output: ,
func (*Reader) Read ¶
Read wraps csv.Reader.Read, creating a map of column name to field value. If the line has fewer columns than Reader.Columns, the map will not contain keys for these columns; thus we can distinguish between missing columns and columns with empty values. If the line has more columns than Reader.Columns, Reader.Read() ignores them.
Example ¶
reader := NewReader(bytes.NewBufferString("first,last\nAlexander,Hamilton")) var err error reader.Columns, err = reader.ReadHeader() if err != nil { fmt.Println(err) return } record, err := reader.Read() if err != nil { fmt.Println(err) return } fmt.Println(record["first"])
Output: Alexander
func (*Reader) ReadAll ¶
ReadAll reads all the remaining records from r. Each record is a map of column name to field value.
Example ¶
reader := NewReader(bytes.NewBufferString("first,last\nAlexander,Hamilton\nAaron,Burr")) var err error reader.Columns, err = reader.ReadHeader() if err != nil { fmt.Println(err) return } records, err := reader.ReadAll() if err != nil { fmt.Println(err) return } fmt.Println(records[1]["last"])
Output: Burr
func (*Reader) ReadHeader ¶
ReadHeader simply wraps csv.Reader.Read().
Example ¶
reader := NewReader(bytes.NewBufferString("first,last\nAlexander,Hamilton")) var err error reader.Columns, err = reader.ReadHeader() if err != nil { fmt.Println(err) return } fmt.Println(reader.Columns[1])
Output: last
Click to show internal directories.
Click to hide internal directories.