csvcodec

package
v0.0.0-...-8a86631 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 17, 2025 License: MIT Imports: 7 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(opts ...Option) *csvCodec

New creates a new CSV codec with the provided options.

Types

type Option

type Option func(*csvCodec)

Option defines a functional option for configuring the CSV codec.

func WithCRLF

func WithCRLF(useCRLF bool) Option

WithCRLF enables or disables CRLF line endings in the CSV output.

func WithCustomDelimiter

func WithCustomDelimiter(delimiter rune) Option

WithCustomDelimiter sets a custom delimiter for the CSV file (default is comma).

func WithCustomHeader

func WithCustomHeader(customHeader []string) Option

WithCustomHeader sets a custom header to be used instead of automatically derived column names.

func WithCustomNULL

func WithCustomNULL(nullValue string) Option

WithCustomNULL sets the string to be used when representing NULL values in the output.

func WithCustomType

func WithCustomType[T any](fn func(v T, metadata scanner.Metadata) tostring.String) Option

WithCustomType registers a custom string conversion function for a specific Go type.

func WithHeader

func WithHeader(writeHeader bool) Option

WithHeader controls whether the CSV output should include a header row.

func WithLimit

func WithLimit(limit int) Option

WithLimit sets a limit on the number of rows to write. A negative value means no limit.

func WithPreProcessorFunc

func WithPreProcessorFunc(fn func(rowID int, row []string) ([]string, bool)) Option

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

func WithWriteHeaderWhenNoData(writeHeaderNoData bool) Option

WithWriteHeaderWhenNoData controls whether a header should be written even when no data rows exist.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL