tableloader

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2024 License: Unlicense Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FormatUnknown = iota
	FormatCSV
	FormatTSV
	FormatJSON
	FormatJSONLines
)

Variables

This section is empty.

Functions

func LoadTable

func LoadTable(r io.Reader, format Format) (Format, Table, error)

LoadTable loads a table from the given reader, with the given format. If format is FormatUnknown, it attempts to auto-detect the format by peeking at the first few bytes of the input. It returns the detected format (or just the parameter format if it's not unknown), the loaded data and an error.

Types

type Format

type Format int

Format is the type of data we're expected to load into a table. The supported formats are: CSV (comma-separated values), TSV (tab-separated values), JSON (a JSON array of objects) and "line per JSON" which has a JSON object on each line. FormatUnknown means that LoadTable will attempt to auto-detect the format based on the first bytes of the input.

func (Format) String

func (f Format) String() string

type Row

type Row = map[string]string

type Table

type Table = []Row

Table is the data format loaded by LoadTable. Each row in the input is represented by a map from column name to column values. For example, for CSV data:

id,name
1,john
2,mary

The loaded table will be a slice of two maps:

[0]: {"id": "1", "name": "john"}
[1]: {"id": "2", "name": "mary"}

For JSON data, the translation is more direct as LoadTable expects JSON representing an array of objects which maps directly to this type.

Jump to

Keyboard shortcuts

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