config

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2024 License: MIT Imports: 5 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

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

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

	// 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
}

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

func New

func New(csvPath string, 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.

Jump to

Keyboard shortcuts

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