producer

package
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package produce contains several methods to generate strings.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckExec added in v0.9.2

func CheckExec(cmd string) error

allow testing an exec command early before setting up the producer.

func Limit

func Limit(ctx context.Context, perSecond float64, in <-chan []string) <-chan []string

Limit limits the number of values per second to the value perSecond. A new goroutine is started, which terminates when in is closed or the context is cancelled.

Types

type Exec added in v0.9.2

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

Exec runs a command and produces each line the command prints.

func NewExec added in v0.9.2

func NewExec(cmd string) *Exec

NewFile creates a new producer from a reader. If seekable is set to false (e.g. for stdin), Yield() returns an error for subsequent runs.

func (*Exec) Yield added in v0.9.2

func (e *Exec) Yield(ctx context.Context, ch chan<- string, count chan<- int) (err error)

Yield runs the command and sends all lines printed by it to ch and the number of items to the channel count. Sending stops and ch and count are closed when an error occurs or the context is cancelled.

type File added in v0.8.0

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

File produces items from a file.

func NewFile added in v0.8.0

func NewFile(rd io.ReadSeeker, seekable bool) *File

NewFile creates a new producer from a reader. If seekable is set to false (e.g. for stdin), Yield() returns an error for subsequent runs.

func (*File) Yield added in v0.8.0

func (f *File) Yield(ctx context.Context, ch chan<- string, count chan<- int) (err error)

Yield sends all lines read from reader to ch, and the number of items to the channel count. Sending stops and ch and count are closed when an error occurs or the context is cancelled.

type Filter

type Filter interface {
	// Count corrects the number of total items to test
	Count(ctx context.Context, in <-chan int) <-chan int

	// Select filters the items
	Select(ctx context.Context, in <-chan []string) <-chan []string
}

Filter selects/rejects items received from a source.

type FilterLimit

type FilterLimit struct {
	Max            int
	CancelProducer func()
}

FilterLimit passes through at most Max values.

func (*FilterLimit) Count

func (f *FilterLimit) Count(ctx context.Context, in <-chan int) <-chan int

Count filters the number of values.

func (*FilterLimit) Select

func (f *FilterLimit) Select(ctx context.Context, in <-chan []string) <-chan []string

Select filters values sent over ch.

type FilterSkip

type FilterSkip struct {
	Skip int
}

FilterSkip skips the first n values sent over the channel.

func (*FilterSkip) Count

func (f *FilterSkip) Count(ctx context.Context, in <-chan int) <-chan int

Count filters the number of values.

func (*FilterSkip) Select

func (f *FilterSkip) Select(ctx context.Context, in <-chan []string) <-chan []string

Select filters values sent over ch.

type Multiplexer added in v0.8.0

type Multiplexer struct {
	Names      []string
	Sources    []Source
	ShowValues []bool
}

Multiplexer takes several sources of values and returns the cross product.

func (*Multiplexer) AddSource added in v0.8.0

func (m *Multiplexer) AddSource(name string, src Source, showValue bool)

AddSource adds a source with the given name.

func (*Multiplexer) Run added in v0.8.0

func (m *Multiplexer) Run(ctx context.Context, ch chan<- []string, count chan<- int) error

Run runs the multiplexer until ctx is cancelled. Both ch and count will be closed when this function returns.

type Range

type Range struct {
	First, Last int
}

Range defines a range of values which should be tested.

func NewRange added in v0.8.0

func NewRange(s string) (r Range, err error)

NewRange parses a range from the string s. Valid formats are `n` and `n-m`.

func (Range) Count

func (r Range) Count() int

Count returns the number of items in the range.

type Ranges

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

Ranges is a source which yields values from several ranges.

func NewRanges added in v0.8.0

func NewRanges(ranges []Range, format string) *Ranges

NewRanges initializes a new source for several ranges. If format is the empty string, "%d" is used.

func (*Ranges) Yield added in v0.8.0

func (r *Ranges) Yield(ctx context.Context, ch chan<- string, count chan<- int) (err error)

Yield sends all lines read from reader to ch, and the number of items to the channel count. Sending stops and ch and count are closed when an error occurs or the context is cancelled. The reader is closed when this function returns.

type Source added in v0.8.0

type Source interface {
	// Yield sends all values to ch, and the number of items to the channel
	// count. Sending stops and ch and count are closed when an error occurs or
	// the context is cancelled. The channel count should be buffered with at a
	// size of at least one, so sending the count does not block.
	Yield(ctx context.Context, ch chan<- string, count chan<- int) error
}

Source produces a sequence of values.

type Value added in v0.8.0

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

File produces items from a file.

func NewValue added in v0.8.0

func NewValue(value string) *Value

NewFile creates a new producer from a reader.

func (*Value) Yield added in v0.8.0

func (f *Value) Yield(ctx context.Context, ch chan<- string, count chan<- int) (err error)

Jump to

Keyboard shortcuts

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