Documentation
¶
Index ¶
- Variables
- func AsStringsArray(val Record, allowString bool) (strs []string, err error)
- func CoerceString(r Record) string
- func NumberToInt(r Record) (int, error)
- func StringEscape(s string) string
- type Array
- type ChannelStream
- type CountingStream
- type CsvStream
- type DiscardSink
- type JSONStream
- type LineStream
- type Object
- type RawStream
- type Record
- type RecordAndError
- type SingletonStream
- type Sink
- type SliceStream
- type Stream
- type StringWriterSink
Constants ¶
This section is empty.
Variables ¶
var ErrNotANumber = errors.New("not a number")
var ErrNotAnInt = errors.New("not an integer")
Functions ¶
func AsStringsArray ¶
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 ¶
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 StringEscape ¶
Types ¶
type Array ¶
type Array = []any
Convenience aliases (for readability)
func CollectStream ¶
CollectStream buffers a Stream into an Array of records.
type ChannelStream ¶ added in v0.1.7
type ChannelStream struct {
Ch chan RecordAndError
}
func (ChannelStream) Next ¶ added in v0.1.7
func (c ChannelStream) Next() (Record, error)
type CountingStream ¶ added in v0.1.7
type CountingStream struct {
Stream
// contains filtered or unexported fields
}
func (*CountingStream) Count ¶ added in v0.1.7
func (c *CountingStream) Count() (n int, done bool)
func (*CountingStream) Next ¶ added in v0.1.7
func (c *CountingStream) Next() (Record, error)
type CsvStream ¶
type CsvStream struct {
// contains filtered or unexported fields
}
func NewCsvReader ¶
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.
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 RawStream ¶
type RawStream struct {
// contains filtered or unexported fields
}
func NewRawStream ¶
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 RecordAndError ¶ added in v0.1.7
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