Documentation ¶
Overview ¶
Package csv contains simple CSV parser
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrEmptyDest = errors.New("Destination slice length must be greater than 1")
ErrEmptyDest is returned by the ReadTo method if empty destination slice was given
View Source
var ErrNilReader = errors.New("Reader is nil")
ErrNilReader is returned when reader struct is nil
Functions ¶
This section is empty.
Types ¶
type Reader ¶
type Reader struct { Comma rune // contains filtered or unexported fields }
Reader is CSV reader struct
func (*Reader) Read ¶
Read reads line from CSV file
Example ¶
fd, err := os.Open("file.csv") if err != nil { fmt.Println(err.Error()) return } defer fd.Close() reader := NewReader(fd) reader.Comma = ',' for { data, err := reader.Read() if err == io.EOF { break } fmt.Printf("%#v\n", data) }
Output:
func (*Reader) ReadTo ¶
ReadTo reads data to given slice
Example ¶
fd, err := os.Open("file.csv") if err != nil { fmt.Println(err.Error()) return } defer fd.Close() reader := NewReader(fd) reader.Comma = ',' data := make([]string, 10) for { err := reader.ReadTo(data) if err == io.EOF { break } fmt.Printf("%#v\n", data) }
Output:
func (*Reader) WithComma ¶ added in v12.69.0
WithComma sets comma (fields delimiter) for CSV reader
Example ¶
fd, err := os.Open("file.csv") if err != nil { fmt.Println(err.Error()) return } defer fd.Close() reader := NewReader(fd).WithComma(',') for { data, err := reader.Read() if err == io.EOF { break } fmt.Printf("%#v\n", data) }
Output:
Click to show internal directories.
Click to hide internal directories.