source

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package source defines where Records come from. Anything that can yield Records (a text file, stdin, a CSV, a network stream) implements Source.

Index

Constants

This section is empty.

Variables

View Source
var ErrDrained = errors.New("source: drained")

ErrDrained is returned by Next when the source has no more records.

Functions

This section is empty.

Types

type InMemory

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

InMemory is a Source backed by a fixed slice of records, for tests and wiring examples.

func NewInMemory

func NewInMemory(records []domain.Record) *InMemory

NewInMemory returns a Source that yields the given records in order.

func (*InMemory) Close

func (s *InMemory) Close() error

Close implements Source. Safe to call concurrently with Next, matching the real sources: the engine closes a source to unwind a blocked read.

func (*InMemory) Next

func (s *InMemory) Next(ctx context.Context) (domain.Record, error)

Next implements Source.

type Source

type Source interface {
	// Next returns the next record. It returns ErrDrained once the source
	// is exhausted, and any other error is a real failure. Returned records
	// must stay valid and unmodified across later Next calls, so a source
	// must not reuse buffers between records. The built-ins copy.
	Next(ctx context.Context) (domain.Record, error)
	// Close releases underlying resources. It is safe to call more than
	// once and concurrently with Next, and it must interrupt a blocked
	// Next. The engine closes a source to unwind a pending read.
	Close() error
}

Source yields Records until it is drained or closed.

Directories

Path Synopsis
Package jsonl implements source.Source over JSON Lines: one JSON object per line.
Package jsonl implements source.Source over JSON Lines: one JSON object per line.
Package text implements source.Source over line-oriented text: files and stdin.
Package text implements source.Source over line-oriented text: files and stdin.

Jump to

Keyboard shortcuts

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