csv

package
v0.0.0-...-96f1409 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2022 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type OpenStringer

type OpenStringer interface {
	fmt.Stringer
	Opener
}

OpenStringer is an Opener which also has a String method which should return the name of the resource being opened (e.g. a file or URL).

type Opener

type Opener interface {
	Open() (io.ReadCloser, error)
}

Opener is an interface to a resource which can be repeatedly Opened (and the returned ReadCloser can be subsequently read). Each call to Open should return a ReadCloser which reads from the beginning of the resource. In the case of an error while reading, Open will be called again to retry reading the entire resource.

type Option

type Option func(*Source)

Option is a functional option to pass to NewSource.

func WithConcurrency

func WithConcurrency(c int) Option

WithConcurrency returns an Option which sets the number of goroutines fetching files simultaneously.

func WithMaxRetries

func WithMaxRetries(maxRetries int) Option

WithMaxRetries returns an Option which sets the max number of retries per file on a Source.

func WithOpenStringers

func WithOpenStringers(os []OpenStringer) Option

WithOpenStringers returns an Option which adds the slice of OpenStringers to the set of data sources a Source will read from.

func WithURLs

func WithURLs(urls []string) Option

WithURLs returns an Option which adds the slice of URLs to the set of data sources a Source will read from. The URLs may be HTTP or local files.

type Source

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

Source satisfies the PDK.Source interface for CSV data. Each line in a CSV file will be returned by a call to record as a map[string]string where the keys are taken from the first line of the CSV. Source is safe for concurrent use.

The Source takes care of retrying failed reads/downloads and making sure not to return duplicate data. TODO: this functionality needs more testing.

func NewSource

func NewSource(options ...Option) *Source

NewSource creates a pdk.Source for CSV data. The source of the raw data can be set by using Options defined in this package. e.g.

src := NewSource(WithURLs([]string{"myfile1.csv", "myfile2.csv", "http://example.com/myfile3.csv"}))

func (*Source) Record

func (c *Source) Record() (interface{}, error)

Record returns a map[string]string representing a single data line of a CSV file. Each key is taken from the header, and each value is parsed from a row - empty fields are skipped.

Jump to

Keyboard shortcuts

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