csv

package
v0.0.0-...-bb33fa6 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddRecord

func AddRecord[T any](result *[]T, data []string, columns map[string]int, options Options) error

func Marshal

func Marshal[T any](dataWriter io.Writer, data []T) error

func MarshalWithOptions

func MarshalWithOptions[T any](dataWriter io.Writer, data []T, options Options) error

func Unmarshal

func Unmarshal[T any](dataReader io.Reader, result *[]T) error

func UnmarshalData

func UnmarshalData[T any](data []byte, result *[]T) error

func UnmarshalDataWithOptions

func UnmarshalDataWithOptions[T any](data []byte, result *[]T, options Options) error

func UnmarshalWithOptions

func UnmarshalWithOptions[T any](dataReader io.Reader, result *[]T, options Options) error

Types

type Adapter

type Adapter interface {
	Kind() reflect.Kind
	IsPointer() bool
	IsNil() bool
	IsStruct() bool
	Set(value any)
	Get() any
	New() Adapter
	Deref() Adapter
	Field(index int) Adapter
	NumField() int
	GetTag(key string) string
	SetString(value string)
	SetInt(value int64)
	SetUint(value uint64)
	SetFloat(value float64)
	SetBool(value bool)
}

func NewReflectAdapter

func NewReflectAdapter(value reflect.Value) Adapter

type Options

type Options struct {
	// Field delimiter (set to ',' by default)
	Delimiter rune
	// Comment, if not 0, is the comment character.
	// Lines beginning with the Comment character without preceding whitespace are ignored.
	// With leading whitespace the Comment character becomes part of the field, even if TrimLeadingSpace is true.
	// Comment must be a valid rune and must not be \r, \n, or the Unicode replacement character (0xFFFD).
	// It must also not be equal to Comma.
	Comment rune
	// FieldsPerRecord is the number of expected fields per record.
	// If FieldsPerRecord is positive, Read requires each record to have the given number of fields.
	// If FieldsPerRecord is 0, Read sets it to the number of fields in the first record, so that future records must have the same field count.
	// If FieldsPerRecord is negative, no check is made and records may have a variable number of fields.
	FieldsPerRecord int
	// If LazyQuotes is true, a quote may appear in an unquoted field and a non-doubled quote may appear in a quoted field.
	LazyQuotes bool
	// If TrimLeadingSpace is true, leading white space in a field is ignored.
	// This is done even if the field delimiter, Comma, is white space.
	TrimLeadingSpace bool
	// True to use \r\n as the line terminator
	UseCRLF bool
	// True for trim spaces while read.
	TrimSpace bool
	// True for trim spaces while read.
	TrimQuotes bool
	// Parse Tag
	Tag string
	// Uses for custom objects (reflect by default)
	AdapterFunc func(reflect.Value) Adapter
}

func (*Options) SetDefaults

func (options *Options) SetDefaults()

type ReflectAdapter

type ReflectAdapter struct {
	// contains filtered or unexported fields
}

func (*ReflectAdapter) Deref

func (ra *ReflectAdapter) Deref() Adapter

func (*ReflectAdapter) Field

func (ra *ReflectAdapter) Field(index int) Adapter

func (*ReflectAdapter) Get

func (ra *ReflectAdapter) Get() any

func (*ReflectAdapter) GetTag

func (ra *ReflectAdapter) GetTag(key string) string

func (*ReflectAdapter) IsNil

func (ra *ReflectAdapter) IsNil() bool

func (*ReflectAdapter) IsPointer

func (ra *ReflectAdapter) IsPointer() bool

func (*ReflectAdapter) IsStruct

func (ra *ReflectAdapter) IsStruct() bool

func (*ReflectAdapter) Kind

func (ra *ReflectAdapter) Kind() reflect.Kind

func (*ReflectAdapter) New

func (ra *ReflectAdapter) New() Adapter

func (*ReflectAdapter) NumField

func (ra *ReflectAdapter) NumField() int

func (*ReflectAdapter) Set

func (ra *ReflectAdapter) Set(value any)

func (*ReflectAdapter) SetBool

func (ra *ReflectAdapter) SetBool(value bool)

func (*ReflectAdapter) SetFloat

func (ra *ReflectAdapter) SetFloat(value float64)

func (*ReflectAdapter) SetInt

func (ra *ReflectAdapter) SetInt(value int64)

func (*ReflectAdapter) SetString

func (ra *ReflectAdapter) SetString(value string)

func (*ReflectAdapter) SetUint

func (ra *ReflectAdapter) SetUint(value uint64)

Jump to

Keyboard shortcuts

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