dataset

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package dataset streams the rows of a data file (`--data`): a CSV file with a header row, or a JSON array of objects. Rows are read one at a time, so memory does not grow with the number of rows.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Each

func Each(path string, fn func(Row) error) error

Each calls fn for every row of the data file at path, stopping at the first error (fn's or the file's).

Types

type Field

type Field struct {
	Name string
	// Raw is the cell text (CSV) or the JSON text of the value (JSON).
	Raw string
	// JSON reports whether Raw is JSON text.
	JSON bool
}

Field is one cell of a row.

type Reader

type Reader interface {
	// Next returns the next row, or io.EOF after the last one.
	Next() (Row, error)
	Close() error
}

Reader reads the rows of a data file.

func Open

func Open(path string) (Reader, error)

Open opens a data file, its format chosen by its extension (.csv or .json).

type Row

type Row struct {
	// Index is the 1-based position of the row in the file.
	Index int
	// Line is the line the row starts on (CSV only; 0 for JSON).
	Line int
	// Fields are the row's cells, in column order (CSV) or sorted by name
	// (JSON).
	Fields []Field
}

Row is one data row.

Jump to

Keyboard shortcuts

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