csv

package
v1.44.0 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package csv extends encoding/csv to understand field names and header row.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Reader

type Reader struct {
	*baseCSV.Reader
	// contains filtered or unexported fields
}

Reader is a CSV reader based on encoding/csv.Reader. Additional functionality supports named access to fields.

func NewReader

func NewReader(r io.Reader, fieldNames ...string) (*Reader, error)

NewReader creates a new CSV reader object. At least one fieldName argument is required since the intent is to use them to access fields in records returned by Read. The wrapped encode/csv.Reader field is visible so its settings can be changed.

func (*Reader) FieldIndex

func (r *Reader) FieldIndex(name string) (int, error)

FieldIndex returns the index of the field specified by name. An error is returned if there is no such field name.

func (*Reader) FieldName

func (r *Reader) FieldName(index int) (string, error)

FieldName returns the name of the field specified by its column index. If the field is not named (not present in fieldNames in NewReader) an error will be return.

func (*Reader) Read

func (r *Reader) Read() (map[string]string, error)

Read consumes the next line and returns a map from field names to field values. Other errors may be returned as documented for encoding/csv.Reader. Specifically, at end of file the map returned is nil and the error is io.EOF.

Jump to

Keyboard shortcuts

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