Documentation
¶
Index ¶
- func DecodeAll[S ~[]E, E any](r io.Reader, dest *S) (err error)
- func DecodeFile[S ~[]E, E any](file string, dest *S) error
- func Export[S ~[]E, E any](fieldnames []string, slice S, w io.Writer) error
- func ExportFile[S ~[]E, E any](fieldnames []string, slice S, file string) error
- func ExportUTF8[S ~[]E, E any](fieldnames []string, slice S, w io.Writer) error
- func ExportUTF8File[S ~[]E, E any](fieldnames []string, slice S, file string) error
- type Reader
- type Writer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecodeFile ¶
DecodeFile decodes each record from file into dest.
func ExportFile ¶
ExportFile writes slice as csv format with fieldnames to file.
func ExportUTF8 ¶
ExportUTF8 writes slice as utf8 csv format with fieldnames to writer w.
Types ¶
type Reader ¶
A Reader reads records from a CSV-encoded file.
func (*Reader) Decode ¶
Decode will unmarshal the current record into dest. If column's value is like "[...]", it will be treated as slice.
func (*Reader) Read ¶
Read reads one record (a slice of fields) from r. If the record has an unexpected number of fields, Read returns the record along with the error [ErrFieldCount]. If the record contains a field that cannot be parsed, Read returns a partial record along with the parse error. The partial record contains all fields read before the error. If there is no data left to be read, Read returns nil, io.EOF. If [Reader.ReuseRecord] is true, the returned slice may be shared between multiple calls to Read.
type Writer ¶
A Writer writes records using CSV encoding.
func (*Writer) Write ¶
Write writes a single CSV record to w along with any necessary quoting after fieldnames is written. A record is a map of strings or a struct. Writes are buffered, so Flush must eventually be called to ensure that the record is written to the underlying io.Writer.
func (*Writer) WriteAll ¶
WriteAll writes multiple CSV records to w using Write and then calls Flush, returning any error from the Flush.
func (*Writer) WriteFields ¶
WriteFields writes fieldnames to w along with necessary utf8bom bytes. The fields must be a non-zero field struct or a non-zero length string slice, otherwise an error will be return. It can be run only once.