Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Convert ¶
func Convert[T any](imported *Imported, mapping ImportMap, opts ...ConvertOption) ([]T, error)
Convert maps rows in Imported into a slice of type T (struct or pointer to struct) using the provided runtime ImportMap. If mapping is nil or empty, fields are mapped automatically using struct tags (`map`) and matching field names. It accepts optional ConvertOption parameters to customize error handling.
Types ¶
type CSVImporter ¶
type CSVImporter struct {
// contains filtered or unexported fields
}
func NewCSVImporter ¶
func NewCSVImporter(reader io.Reader, opts ...CSVOption) *CSVImporter
func (*CSVImporter) Import ¶
func (ci *CSVImporter) Import() (*Imported, error)
func (*CSVImporter) ReadHeaders ¶
func (ci *CSVImporter) ReadHeaders() ([]string, error)
type CSVOption ¶ added in v0.1.2
func WithComment ¶ added in v0.1.2
WithComment sets the comment character.
func WithFieldsPerRecord ¶ added in v0.1.2
WithFieldsPerRecord sets the expected number of fields per record.
func WithLazyQuotes ¶ added in v0.1.2
WithLazyQuotes configures the reader to allow lazy quotes.
func WithTrimLeadingSpace ¶ added in v0.1.2
WithTrimLeadingSpace configures the reader to trim leading whitespace.
type ConvertOption ¶
type ConvertOption func(*convertConfig)
ConvertOption allows customizing the behavior of Convert.
func WithErrorHandler ¶
func WithErrorHandler(handler func(err error, rowIndex int, row map[string]string) error) ConvertOption
WithErrorHandler provides a custom callback to handle conversion errors on a per-row basis. If the callback returns nil, the row is skipped and conversion continues with the next row. If the callback returns a non-nil error, conversion is aborted immediately and that error is returned.
func WithSkipOnError ¶
func WithSkipOnError() ConvertOption
WithSkipOnError is a convenience option that tells Convert to silently skip any rows that fail conversion.
type ImportMap ¶
ImportMap defines a runtime mapping from input source keys (e.g. CSV header names) to exact struct field names.
type Importer ¶
Importer defines the interface for reading different file formats into Imported data.
type XLSXImporter ¶
type XLSXImporter struct {
// contains filtered or unexported fields
}
func NewXLSXImporter ¶
func NewXLSXImporter(reader io.Reader, sheet string) *XLSXImporter
func (*XLSXImporter) Close ¶ added in v0.1.2
func (xi *XLSXImporter) Close() error
Close closes the underlying excelize File if it was opened.
func (*XLSXImporter) GetSheets ¶ added in v0.1.2
func (xi *XLSXImporter) GetSheets() ([]string, error)
GetSheets returns a list of sheet names in the XLSX file.
func (*XLSXImporter) Import ¶
func (xi *XLSXImporter) Import() (*Imported, error)
func (*XLSXImporter) ReadHeaders ¶
func (xi *XLSXImporter) ReadHeaders() ([]string, error)
func (*XLSXImporter) SetSheet ¶ added in v0.1.2
func (xi *XLSXImporter) SetSheet(sheet string)
SetSheet changes the target sheet to be imported and clears any cached import data.