Documentation
¶
Overview ¶
Package csvcodec provides an implementation of the Codec interface for writing data in CSV (Comma-Separated Values) format. It supports custom delimiters, NULL handling, optional headers, row preprocessing, and type-specific string conversion.
Index ¶
- func New(opts ...Option) *csvCodec
- type Option
- func WithCRLF(useCRLF bool) Option
- func WithCustomDelimiter(delimiter rune) Option
- func WithCustomHeader(customHeader []string) Option
- func WithCustomNULL(nullValue string) Option
- func WithCustomType[T any](fn func(v T, metadata scanner.Metadata) tostring.String) Option
- func WithHeader(writeHeader bool) Option
- func WithLimit(limit int) Option
- func WithPreProcessorFunc(fn func(rowID int, row []string) ([]string, bool)) Option
- func WithWriteHeaderWhenNoData(writeHeaderNoData bool) Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Option ¶
type Option func(*csvCodec)
Option defines a functional option for configuring the CSV codec.
func WithCustomDelimiter ¶
WithCustomDelimiter sets a custom delimiter for the CSV file (default is comma).
func WithCustomHeader ¶
WithCustomHeader sets a custom header to be used instead of automatically derived column names.
func WithCustomNULL ¶
WithCustomNULL sets the string to be used when representing NULL values in the output.
func WithCustomType ¶
WithCustomType registers a custom string conversion function for a specific Go type.
func WithHeader ¶
WithHeader controls whether the CSV output should include a header row.
func WithLimit ¶
WithLimit sets a limit on the number of rows to write. A negative value means no limit.
func WithPreProcessorFunc ¶
WithPreProcessorFunc sets a function to preprocess or filter each row before writing. The function receives the row ID and the row values, and can return modified values or skip the row.
func WithWriteHeaderWhenNoData ¶
WithWriteHeaderWhenNoData controls whether a header should be written even when no data rows exist.