record

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotANumber = errors.New("not a number")
View Source
var ErrNotAnInt = errors.New("not an integer")

Functions

func AsStringsArray

func AsStringsArray(val Record, allowString bool) (strs []string, err error)

AsStringsArray converts val to an array of strings:

  • If nil, returns empty array
  • If array with all elements as strings, returns as string array
  • If string and allowString == true, return as a single-element array
  • Otherwise, return an error

func CoerceString

func CoerceString(r Record) string

CoerceString formats r as a string as follows:

  • string is returned as-is
  • all other types are marshaled and returned as raw JSON

func NumberToInt

func NumberToInt(r Record) (int, error)

func StringEscape

func StringEscape(s string) string

Types

type Array

type Array = []any

Convenience aliases (for readability)

func CollectStream

func CollectStream(s Stream) (arr Array, err error)

CollectStream buffers a Stream into an Array of records.

type CsvStream

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

func NewCsvReader

func NewCsvReader(r io.Reader, comma rune, raw bool, concurrent bool) *CsvStream

NewCsvReader creates a Stream by parsing the input io.Reader as comma-separated value format. comma is the separator (should be ',' for true CSV). If raw, no CSV header is expected, and each line becomes a simple Array from field values; otherwise, the first line is interpreted as a header defining field names, and each line becomes an Object using those field names. Next is safe for concurrent use by multiple goroutines iff concurrent is true.

func (*CsvStream) Next

func (c *CsvStream) Next() (Record, error)

type DiscardSink

type DiscardSink struct{}

func (DiscardSink) Sink

func (DiscardSink) Sink(Record) error

type JSONStream

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

func NewJSONStream

func NewJSONStream(r io.Reader) *JSONStream

func (*JSONStream) Next

func (j *JSONStream) Next() (out Record, err error)

type LineStream

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

func NewLineStream

func NewLineStream(r io.Reader) *LineStream

func (*LineStream) Next

func (l *LineStream) Next() (out Record, err error)

type Object

type Object = map[string]any

Convenience aliases (for readability)

type RawStream

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

func NewRawStream

func NewRawStream(r io.Reader) *RawStream

func (*RawStream) Next

func (r *RawStream) Next() (Record, error)

type Record

type Record = any

Record is a single data item. It is always matches one of these types:

untyped nil, bool, float64, string, []any, map[string]any

json.Marshal/json.Unmarshal may be used on Record at will.

type SingletonStream

type SingletonStream struct {
	Rec Record
	// contains filtered or unexported fields
}

func (*SingletonStream) Next

func (t *SingletonStream) Next() (Record, error)

type Sink

type Sink interface {
	// Sink accepts a Record, with implementation-dependent effect. It is safe for concurrent use by multiple goroutines.
	Sink(rec Record) error
}

A Sink consumes Records.

type SliceStream

type SliceStream struct {
	Records []Record
	// contains filtered or unexported fields
}

func (*SliceStream) Next

func (a *SliceStream) Next() (out Record, err error)

type Stream

type Stream interface {
	// Next returns the next Record in the stream, or io.EOF if end-of-stream, or other error if one occurred.
	// Next never returns both a Record and a non-nil error (as nil is indistinguishable from a real null Record).
	// Once Next returns io.EOF, every subsequent call will also return io.EOF.
	// Next is safe for concurrent use by multiple goroutines, although no guarantee of Record ordering is given under
	// concurrent access.
	Next() (Record, error)
}

type StringWriterSink

type StringWriterSink struct {
	Writer io.StringWriter
	// contains filtered or unexported fields
}

func (*StringWriterSink) Sink

func (s *StringWriterSink) Sink(r Record) error

Jump to

Keyboard shortcuts

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