config

package
v0.6.4 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2025 License: MIT Imports: 9 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrEmptyFirstLine = fmt.Errorf("empty first line")
View Source
var ErrFileMissing = errors.New("provide valid input file path")
View Source
var ErrNoHeaders = errors.New("provide headers manually")
View Source
var ErrNoHeadersOrColSep = errors.New("provide headers and/or delimiter manually")
View Source
var ErrNoInputOrOutput = errors.New("no input or output provided")

Functions

This section is empty.

Types

type Config

type Config struct {
	// Path to the CSV file.
	Path string

	// Writer can be used for writing output instead of file.
	Writer io.Writer

	// Headers are the names of fields in the CSV file.
	Headers []string

	// SkipHeaders
	SkipHeaders bool

	// ColSep is the delimiter character used in the CSV file.
	ColSep rune

	// FieldsNum is the expected number of fields in each row.
	FieldsNum int

	// BadRowMode specifies how to handle rows with an incorrect
	// number of fields. Options include processing, ignoring, or
	// raising an error (default).
	BadRowMode gnfmt.BadRow

	// WithQuotes is true if `"` is used when need arises to
	// protect field separators, new lines inside a field.
	WithQuotes bool
}

Config provides settings for processing CSV data, including file path, headers, delimiter, field count, and bad row handling mode.

func New

func New(opts ...Option) (Config, error)

New creates a new Config by analyzing the first line of a CSV file to determine the delimiter and headers. Options can be provided to override the detected settings.

func (Config) Update

func (c Config) Update(opts ...Option) Config

Update creates a copy of the Config and applies the provided options to it, returning the updated copy.

type Option

type Option func(*Config)

Option is a function that modifies a Config.

func OptBadRowMode

func OptBadRowMode(br gnfmt.BadRow) Option

OptBadRowMode sets the BadRowMode field of the Config.

func OptColSep

func OptColSep(r rune) Option

OptColSep sets the ColSep field of the Config.

func OptFieldsNum

func OptFieldsNum(i int) Option

OptFieldsNum sets the FieldsNum field of the Config.

func OptHeaders

func OptHeaders(ss []string) Option

OptHeaders sets the Headers field of the Config.

func OptPath

func OptPath(s string) Option

OptPath sets the Path field of the Config.

func OptSkipHeaders added in v0.5.6

func OptSkipHeaders(b bool) Option

OptSkipHeaders sets OptSkipHeaders field of the config.

func OptWithQuotes added in v0.5.3

func OptWithQuotes(b bool) Option

OptWithQuotes sets WithQuotes field of the Config.

func OptWriter added in v0.5.1

func OptWriter(w io.Writer) Option

OptWriter sets Writer field of the Config.

Jump to

Keyboard shortcuts

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