csvutil

package module
v0.0.0-...-9ce1ce7 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2022 License: Apache-2.0 Imports: 9 Imported by: 0

README

csvutil

A [un]marshaling utility for translating between CSV data and Go structs

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Decoder

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

Decoder manages reading data from a CSV into tagged structs.

func NewDecoder

func NewDecoder(r io.Reader, dest interface{}) (Decoder, error)

NewDecoder initializes itself with the headers of the CSV file to build mappings to read data into structs.

func NewDecoderFromCSVReader

func NewDecoderFromCSVReader(csvR *csv.Reader, dest interface{}) (Decoder, error)

NewDecoderFromCSVReader intializes a decoder using the given csv.Reader. This allows the caller to configure options on the csv.Reader (e.g. what delimiter to use) instead of using the defaults.

func (Decoder) MatchedHeaders

func (d Decoder) MatchedHeaders() []string

MatchedHeaders returns an array of strings (headers) using the Decoder mappings created during decoder initialization. Returns an empty array when no headers are matched.

func (Decoder) Read

func (d Decoder) Read(dest interface{}) error

Read decodes data from a CSV row into a struct. The struct must be passed as a pointer into Read. When there is no data left in the reader, an `io.EOF` is returned.

type Encoder

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

Encoder manages writing a tagged struct into a CSV

func NewEncoder

func NewEncoder(w io.Writer, dest interface{}) (Encoder, error)

NewEncoder prepares mappings from struct to CSV based on struct tags.

func NewEncoderFromCSVWriter

func NewEncoderFromCSVWriter(csvW *csv.Writer, dest interface{}) (Encoder, error)

NewEncoderFromCSVWriter intializes an encoder using the given csv.Writer. This allows the caller to configure options on the csv.Writer (e.g. what delimiter to use) instead of using the defaults.

func (Encoder) Write

func (e Encoder) Write(src interface{}) error

Write encodes the values of a struct into a CSV row and writes to the underlying io.writer.

Jump to

Keyboard shortcuts

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