Documentation ¶
Index ¶
- type ClientReader
- func (reader *ClientReader) Read() ([]string, error)
- func (reader *ClientReader) ReadAll() ([][]string, error)
- func (reader *ClientReader) ReadRowFromFile(structure interface{}) error
- func (reader *ClientReader) ReadRowFromFileWithNames(names []string, structure interface{}) error
- func (reader *ClientReader) ReadRowsFromFile(list interface{}) error
- func (reader *ClientReader) ReadRowsFromFileWithNames(names []string, list interface{}) error
- type ClientReaderOption
- type ClientReaderOptionFunc
- func WithReaderComma(comma rune) ClientReaderOptionFunc
- func WithReaderComment(comment rune) ClientReaderOptionFunc
- func WithReaderFieldsPerRecord(fieldsPerRecord int) ClientReaderOptionFunc
- func WithReaderLazyQuotes(lazyQuotes bool) ClientReaderOptionFunc
- func WithReuseRecord(reuse bool) ClientReaderOptionFunc
- func WithTrimLeadingSpace(trimLeadingSpace bool) ClientReaderOptionFunc
- type ClientWriter
- type ClientWriterOption
- type ClientWriterOptionFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ClientReader ¶
type ClientReader struct {
// contains filtered or unexported fields
}
ClientReader a reader client is used to read and unmarshal file of csv
func NewClientReader ¶
func NewClientReader(reader io.Reader, opts ...ClientReaderOptionFunc) *ClientReader
func (*ClientReader) Read ¶
func (reader *ClientReader) Read() ([]string, error)
Read Read one line at a time
func (*ClientReader) ReadAll ¶
func (reader *ClientReader) ReadAll() ([][]string, error)
ReadAll Read all the remaining lines in sequence
func (*ClientReader) ReadRowFromFile ¶
func (reader *ClientReader) ReadRowFromFile(structure interface{}) error
ReadRowFromFile Read a row of lines and parse it into each field of the structure in the order of columns.
structure: The parameter structure is a structure pointer
func (*ClientReader) ReadRowFromFileWithNames ¶
func (reader *ClientReader) ReadRowFromFileWithNames(names []string, structure interface{}) error
ReadRowFromFileWithNames Read a row of lines and parse the data into the corresponding field name of the structure in the order specified by names.
names: The parameter names is field names of structure in order to specify column of file to structure
structure: The parameter structure is a structure pointer
func (*ClientReader) ReadRowsFromFile ¶
func (reader *ClientReader) ReadRowsFromFile(list interface{}) error
ReadRowsFromFile Read rows of remaining lines and parse it into each field of the structure in the order of columns.
list: The parameter list is a list pointer,the item of list must be a structure or a structure pointer
func (*ClientReader) ReadRowsFromFileWithNames ¶
func (reader *ClientReader) ReadRowsFromFileWithNames(names []string, list interface{}) error
ReadRowsFromFileWithNames Read rows of lines and parse the data into the corresponding field name of the structure in the order specified by names.
names: The parameter names is field names of structure in order to specify column of file to structure
list: The parameter list is a list pointer,the item of list must be a structure or a structure pointer
type ClientReaderOption ¶
type ClientReaderOption struct { // Comma is the field delimiter. // It is set to comma (',') by NewReader. // Comma must be a valid rune and must not be \r, \n, // or the Unicode replacement character (0xFFFD). Comma rune // Comment, if not 0, is the comment character. Lines beginning with the // Comment character without preceding whitespace are ignored. // With leading whitespace the Comment character becomes part of the // field, even if TrimLeadingSpace is true. // Comment must be a valid rune and must not be \r, \n, // or the Unicode replacement character (0xFFFD). // It must also not be equal to Comma. Comment rune // FieldsPerRecord is the number of expected fields per record. // If FieldsPerRecord is positive, Read requires each record to // have the given number of fields. If FieldsPerRecord is 0, Read sets it to // the number of fields in the first record, so that future records must // have the same field count. If FieldsPerRecord is negative, no check is // made and records may have a variable number of fields. FieldsPerRecord int // If LazyQuotes is true, a quote may appear in an unquoted field and a // non-doubled quote may appear in a quoted field. LazyQuotes bool // If TrimLeadingSpace is true, leading white space in a field is ignored. // This is done even if the field delimiter, Comma, is white space. TrimLeadingSpace bool // ReuseRecord controls whether calls to Read may return a slice sharing // the backing array of the previous call's returned slice for performance. // By default, each call to Read returns newly allocated memory owned by the caller. ReuseRecord bool }
type ClientReaderOptionFunc ¶
type ClientReaderOptionFunc func(opt *ClientReaderOption)
func WithReaderComma ¶
func WithReaderComma(comma rune) ClientReaderOptionFunc
func WithReaderComment ¶
func WithReaderComment(comment rune) ClientReaderOptionFunc
func WithReaderFieldsPerRecord ¶
func WithReaderFieldsPerRecord(fieldsPerRecord int) ClientReaderOptionFunc
func WithReaderLazyQuotes ¶
func WithReaderLazyQuotes(lazyQuotes bool) ClientReaderOptionFunc
func WithReuseRecord ¶
func WithReuseRecord(reuse bool) ClientReaderOptionFunc
func WithTrimLeadingSpace ¶
func WithTrimLeadingSpace(trimLeadingSpace bool) ClientReaderOptionFunc
type ClientWriter ¶
type ClientWriter struct {
// contains filtered or unexported fields
}
ClientWriter a writer client is used to write data to csv
func NewClientWriter ¶
func NewClientWriter(writer io.Writer, opts ...ClientWriterOptionFunc) *ClientWriter
func (*ClientWriter) WriteRow2File ¶
func (writer *ClientWriter) WriteRow2File(structure interface{}, setTitle ...bool) error
WriteRow2File Write a line of data to a file
structure: The parameter data is a structure pointer
func (*ClientWriter) WriteRows2File ¶
func (writer *ClientWriter) WriteRows2File(list interface{}, setTitle ...bool) error
WriteRows2File Write multiple lines of data to a file
list: The parameter list is a list pointer,the item of list must be a structure or a structure pointer
func (*ClientWriter) WriteString2File ¶
func (writer *ClientWriter) WriteString2File(data [][]string) error
WriteString2File 向CSV文件中写入文本数据
data 切片每个元素代表一行,每行元素还是一个切片,其中每个元素代表一列
type ClientWriterOption ¶
type ClientWriterOptionFunc ¶
type ClientWriterOptionFunc func(*ClientWriterOption)
func WithWriterComma ¶
func WithWriterComma(comma rune) ClientWriterOptionFunc
func WithWriterUseCRLF ¶
func WithWriterUseCRLF(useCRLF bool) ClientWriterOptionFunc