csvee

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2021 License: MIT Imports: 9 Imported by: 0

README

csvee

encoding/csv wrapper that supports unmarshaling to structs

TODO: support marshaling from struct to CSV

Documentation

Index

Constants

View Source
const TimeFormatUnix string = "unix"

Variables

View Source
var (
	ErrColumnNamesMismatch    = errors.New("The number of column names does not match the number of fieldsin the record.")
	ErrUnsupportedTargetType  = errors.New("Target interface must be of type struct or map.")
	ErrInvalidFieldType       = errors.New("Struct field type must be int*, float*, bool, string, time, or a slice.")
	ErrReadAllNotSlicePointer = errors.New("The argument to ReadAll must be a pointer to a slice of structs.")
	ErrReadTargetNil          = errors.New("The argument to Reader.Read[All] must be non nil.")
)

Functions

This section is empty.

Types

type Reader

type Reader struct {
	CSVReader     *csv.Reader
	ColumnNames   []string
	ColumnFormats map[string]string
}

Reader embeds *csv.Reader and contains the column names of the CSV data that is to be read.

func NewReader

func NewReader(
	r io.Reader,
	options ...*ReaderOptions,
) (*Reader, error)

NewReader returns a new Reader that reads from r.

func (*Reader) Read

func (r *Reader) Read(v interface{}) error

Read reads the next line of the CSV and puts in into a struct.

func (*Reader) ReadAll

func (r *Reader) ReadAll(v interface{}) error

ReadAll reads all the lines of the CSV and puts in into a slice of structs.

type ReaderOptions

type ReaderOptions struct {
	ReadHeaders   bool
	ColumnNames   []string
	ColumnFormats map[string]string
}

ReaderOptions can be provided to the Reader constructor.

Jump to

Keyboard shortcuts

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