iterator

package
v2.39.3 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrEmptyPipeInput = errors.New("iterator: empty pipe input")

ErrEmptyPipeInput pipe input is being used but it is empty

View Source
var ErrNoPipeInput = errors.New("iterator: no piped input")

ErrNoPipeInput is an error when there is no piped input on standard input

Functions

func DummyFormatter

func DummyFormatter(v []byte) []byte

func IsEmptyPipeInputError

func IsEmptyPipeInputError(err error) bool

func MarshalJSON

func MarshalJSON(i Iterator) (line []byte, err error)

func PeekReader

func PeekReader(r *bufio.Reader) error

PeekReader check if the reader contains empty input or not An error will be returned if the reader does not contain any data, or the first character is whitespace

Types

type BufioIterator

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

BufioIterator is a wrapper around a bufio.Reader which conforms to the Iterator interface

func NewBufioIterator

func NewBufioIterator(reader *bufio.Reader) *BufioIterator

NewBufioIterator returns a new iterator from a Bufio reader

func (*BufioIterator) GetNext

func (i *BufioIterator) GetNext() (line []byte, input interface{}, err error)

GetNext returns the next line in the buffer

func (*BufioIterator) IsBound

func (i *BufioIterator) IsBound() bool

IsBound return true if the iterator is bound

func (*BufioIterator) MarshalJSON

func (i *BufioIterator) MarshalJSON() (line []byte, err error)

MarshalJSON return the value in a json compatible value

type CSVFileContentsIterator added in v2.33.0

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

CSVFileContentsIterator to iterator over the contents of a csv file

func (*CSVFileContentsIterator) DetectDelimiter added in v2.33.0

func (i *CSVFileContentsIterator) DetectDelimiter() (rune, error)

func (*CSVFileContentsIterator) GetNext added in v2.33.0

func (i *CSVFileContentsIterator) GetNext() (line []byte, input interface{}, err error)

GetNext returns the next line in the buffer

func (*CSVFileContentsIterator) IsBound added in v2.33.0

func (i *CSVFileContentsIterator) IsBound() bool

IsBound return true if the iterator is bound

func (*CSVFileContentsIterator) MarshalJSON added in v2.33.0

func (i *CSVFileContentsIterator) MarshalJSON() (line []byte, err error)

MarshalJSON return the value in a json compatible value

func (*CSVFileContentsIterator) SetColumns added in v2.33.0

func (i *CSVFileContentsIterator) SetColumns(total int)

type CompositeIterator

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

func NewCompositeStringIterator

func NewCompositeStringIterator(iterator Iterator, format string) *CompositeIterator

NewCompositeStringIterator create a new string iterator built from an already existing iterator

func (*CompositeIterator) GetNext

func (i *CompositeIterator) GetNext() (line []byte, input interface{}, err error)

GetNext will count through the values and return them one by one

func (*CompositeIterator) GetValueByInput

func (i *CompositeIterator) GetValueByInput(input []byte) (line []byte, err error)

func (*CompositeIterator) IsBound

func (i *CompositeIterator) IsBound() bool

IsBound return true if the iterator is bound

type EmptyIterator

type EmptyIterator struct{}

EmptyIterator is an empty iterator that always returns no value

func (*EmptyIterator) GetNext

func (i *EmptyIterator) GetNext() (line []byte, input interface{}, err error)

GetNext always return io.EOF

func (*EmptyIterator) IsBound

func (i *EmptyIterator) IsBound() bool

IsBound return true if the iterator is bound

func (*EmptyIterator) MarshalJSON

func (i *EmptyIterator) MarshalJSON() (line []byte, err error)

MarshalJSON return the value in a json compatible value

type FileContentsIterator

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

FileContentsIterator is a wrapper around a bufio.Reader which conforms to the Iterator interface

func (*FileContentsIterator) GetNext

func (i *FileContentsIterator) GetNext() (line []byte, input interface{}, err error)

GetNext returns the next line in the buffer

func (*FileContentsIterator) IsBound

func (i *FileContentsIterator) IsBound() bool

IsBound return true if the iterator is bound

func (*FileContentsIterator) MarshalJSON

func (i *FileContentsIterator) MarshalJSON() (line []byte, err error)

MarshalJSON return the value in a json compatible value

type Filter

type Filter func([]byte) bool

Filter is a funciton applied on every iteration. Returning False will end the iterator

type Formatter

type Formatter func([]byte) []byte

Formatter a function to transform input pipeline value and returns the formatted value as output

func NewStringFormatter added in v2.15.0

func NewStringFormatter(format string) Formatter

type FuncIterator

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

FuncIterator is generic iterator which executes a function on every iteration

func NewFuncIterator

func NewFuncIterator(next func(int64) (string, error), n int64) *FuncIterator

NewFuncIterator return an iterator based on the given function

func NewRelativeDateIterator

func NewRelativeDateIterator(relative string, encode bool, layout string, format ...string) *FuncIterator

NewRelativeDateIterator returns a relative date iterator which can generate dates based on time.Now when the value is retrieved

func NewRelativeTimeIterator

func NewRelativeTimeIterator(relative string, encode bool, utc bool, format ...string) *FuncIterator

NewRelativeTimeIterator returns a relative time iterator which can generate timestamps based on time.Now when the value is retrieved

func (*FuncIterator) GetNext

func (i *FuncIterator) GetNext() (line []byte, input interface{}, err error)

GetNext will count through the values and return them one by one

func (*FuncIterator) IsBound

func (i *FuncIterator) IsBound() bool

IsBound return true if the iterator is bound

func (*FuncIterator) MarshalJSON

func (i *FuncIterator) MarshalJSON() (line []byte, err error)

MarshalJSON return the value in a json compatible value

type InfiniteSliceIterator

type InfiniteSliceIterator struct {
	SliceIterator
}

InfiniteSliceIterator is iterates over a given array and once the last element is return, it sets the index back to the first element. It will continue indefinitely

func NewInfiniteSliceIterator

func NewInfiniteSliceIterator(values []string) *InfiniteSliceIterator

NewInfiniteSliceIterator creates a repeater which returns the slice items and wraps around indefinitely

func (*InfiniteSliceIterator) GetNext

func (i *InfiniteSliceIterator) GetNext() (line []byte, input interface{}, err error)

GetNext will count through the values and return them one by one

type Iterator

type Iterator interface {
	GetNext() (line []byte, input interface{}, err error)

	// IsBound return true if the iterator is bound
	IsBound() bool
}

Iterator is a simple interfact where the next value can be returned.

func NewCSVFileContentsIterator added in v2.33.0

func NewCSVFileContentsIterator(path string, delimiter string, hasHeaders bool, headers []string) (Iterator, error)

NewCSVFileContentsIterator returns a file contents iterator

func NewFileContentsIterator

func NewFileContentsIterator(path string, format ...string) (Iterator, error)

NewFileContentsIterator returns a file contents iterator

func NewJSONPipeIterator

func NewJSONPipeIterator(in io.Reader, pipeOpts *PipeOptions, filter ...Filter) (Iterator, error)

NewJSONPipeIterator returns a new pipe iterator

func NewPipeIterator

func NewPipeIterator(in io.Reader, filter ...Filter) (Iterator, error)

NewPipeIterator returns a new pipe iterator

type OverrideIterator

type OverrideIterator struct {
	OverrideValue Iterator
	// contains filtered or unexported fields
}

func NewOverrideIterator

func NewOverrideIterator(valueIterator Iterator, overrideValue Iterator) *OverrideIterator

NewOverrideIterator create a new iterator which can be override with other values

func (*OverrideIterator) GetNext

func (i *OverrideIterator) GetNext() (value []byte, input interface{}, err error)

func (*OverrideIterator) IsBound

func (i *OverrideIterator) IsBound() bool

IsBound return true if the iterator is bound

func (*OverrideIterator) MarshalJSON

func (i *OverrideIterator) MarshalJSON() (line []byte, err error)

MarshalJSON return the value in a json compatible value

type PipeIterator

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

PipeIterator is a thread safe iterator to retrieve the input values from piped standard input

func (*PipeIterator) GetNext

func (i *PipeIterator) GetNext() (line []byte, input interface{}, err error)

GetNext returns the next line from the pipeline

func (*PipeIterator) IsBound

func (i *PipeIterator) IsBound() bool

IsBound return true if the iterator is bound

func (*PipeIterator) MarshalJSON

func (i *PipeIterator) MarshalJSON() (line []byte, err error)

MarshalJSON return the value in a json compatible value

type PipeOptions

type PipeOptions struct {
	// Property name if the input data is json
	Properties []string

	// AllowEmpty allow pipeline items without any matching properties.
	AllowEmpty bool

	// Validator to be applied on each item
	Validator Validator

	// Formatter
	Formatter Formatter

	// Format simple custom format string
	Format string
}

PipeOptions additional options on how to interpret the piped data

type RangeIterator

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

RangeIterator returns value sequentially from start to end

func NewRangeIterator

func NewRangeIterator(start, end, step int64) *RangeIterator

NewRangeIterator creates a new range iterator to step through values from a start to end with step

func (*RangeIterator) GetNext

func (i *RangeIterator) GetNext() (line []byte, input interface{}, err error)

GetNext returns the next value from the range

func (*RangeIterator) IsBound

func (i *RangeIterator) IsBound() bool

IsBound return true if the iterator is bound

func (*RangeIterator) MarshalJSON

func (i *RangeIterator) MarshalJSON() (line []byte, err error)

MarshalJSON return the value in a json compatible value

type RepeatIterator

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

RepeatIterator is an empty iterator that always returns no value

func NewRepeatIterator

func NewRepeatIterator(value string, n int64) *RepeatIterator

NewRepeatIterator creates a repeater which returns the same value n times before returns io.EOF. If n is set to 0, then it will repeat forever

func (*RepeatIterator) GetNext

func (i *RepeatIterator) GetNext() (line []byte, input interface{}, err error)

GetNext will count through the values and return them one by one

func (*RepeatIterator) IsBound

func (i *RepeatIterator) IsBound() bool

IsBound return true if the iterator is bound

func (*RepeatIterator) MarshalJSON

func (i *RepeatIterator) MarshalJSON() (line []byte, err error)

MarshalJSON return the value in a json compatible value

type SliceIterator

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

SliceIterator is iterates over a given array

func NewSliceIterator

func NewSliceIterator(values []string, format ...string) *SliceIterator

NewSliceIterator creates a repeater which returns the slice items before returns io.EOF

func (*SliceIterator) GetNext

func (i *SliceIterator) GetNext() (line []byte, input interface{}, err error)

GetNext will count through the values and return them one by one

func (*SliceIterator) IsBound

func (i *SliceIterator) IsBound() bool

IsBound return true if the iterator is bound

func (*SliceIterator) MarshalJSON

func (i *SliceIterator) MarshalJSON() (line []byte, err error)

MarshalJSON return the value in a json compatible value

type UntypedIterator

type UntypedIterator interface {
	GetNext() (out interface{}, err error)
}

type Validator

type Validator func([]byte) error

Validator is a function applied to every iterator. If it returns an error then the error will be passed on. This can be used if you want to apply simple validation logic to each item, i.e. validate that it is an id like value or not.

Jump to

Keyboard shortcuts

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