fakenews

package
v0.0.0-...-41a33bd Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2023 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StructTagName = "fakenews"
)

Variables

This section is empty.

Functions

func ConsumeGenerator

func ConsumeGenerator[T any](g Generator[T]) []T

func ConsumeUntil

func ConsumeUntil[T any](g Generator[T], n int) []T

func Fake

func Fake[T any](val T, rules ...Rule[T]) (T, error)

func InfiniteStream

func InfiniteStream[T any](ctx context.Context, seed T, in chan T, rules ...Rule[T]) error

Types

type Generator

type Generator[T any] interface {
	Next() (T, bool)
	Iter() Generator[T]
}

func ChainRandom

func ChainRandom[T any](limit int, g ...Generator[T]) Generator[T]

func ChainRoundRobin

func ChainRoundRobin[T any](limit int, g ...Generator[T]) Generator[T]

func GeneratorFromIO

func GeneratorFromIO[T any](file io.ReadSeeker, parser LineParser[T]) Generator[T]

func Infinite

func Infinite[T any](g Generator[T]) Generator[T]

func RulesToGenerator

func RulesToGenerator[T any](t T, rs ...Rule[T]) Generator[T]

type InfiniteGenerator

type InfiniteGenerator[T any] struct {
	// contains filtered or unexported fields
}

func (InfiniteGenerator[T]) Iter

func (i InfiniteGenerator[T]) Iter() Generator[T]

func (InfiniteGenerator[T]) Next

func (i InfiniteGenerator[T]) Next() (T, bool)

type LineGenerator

type LineGenerator[T any] struct {
	// contains filtered or unexported fields
}

func (LineGenerator[T]) Iter

func (l LineGenerator[T]) Iter() Generator[T]

func (LineGenerator[T]) Next

func (l LineGenerator[T]) Next() (T, bool)

type LineParser

type LineParser[T any] func(line []byte) T

type LineReaderSeeker

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

func NewLineReaderSeeker

func NewLineReaderSeeker(rs io.ReadSeeker) *LineReaderSeeker

func (*LineReaderSeeker) Lines

func (lrs *LineReaderSeeker) Lines() (int, error)

Updated Lines function

func (*LineReaderSeeker) RandomLine

func (lrs *LineReaderSeeker) RandomLine() (string, error)

func (*LineReaderSeeker) Read

func (lrs *LineReaderSeeker) Read(p []byte) (n int, err error)

func (*LineReaderSeeker) Seek

func (lrs *LineReaderSeeker) Seek(offset int64, whence int) (int64, error)

func (*LineReaderSeeker) SeekLine

func (lrs *LineReaderSeeker) SeekLine(lineNumber int, whence int) error

type OneFieldRule

type OneFieldRule[T any] struct {
	// contains filtered or unexported fields
}

func NewRule

func NewRule[T any](fn string, runner Runner[T]) OneFieldRule[T]

func (OneFieldRule[T]) FieldName

func (o OneFieldRule[T]) FieldName() string

func (OneFieldRule[T]) Run

func (o OneFieldRule[T]) Run(current *T) (T, error)

type RandomChainGenerator

type RandomChainGenerator[T any] struct {
	// contains filtered or unexported fields
}

func (RandomChainGenerator[T]) Iter

func (c RandomChainGenerator[T]) Iter() Generator[T]

func (RandomChainGenerator[T]) Next

func (c RandomChainGenerator[T]) Next() (T, bool)

type RoundRobinChainGenerator

type RoundRobinChainGenerator[T any] struct {
	// contains filtered or unexported fields
}

func (RoundRobinChainGenerator[T]) Iter

func (c RoundRobinChainGenerator[T]) Iter() Generator[T]

func (RoundRobinChainGenerator[T]) Next

func (c RoundRobinChainGenerator[T]) Next() (T, bool)

type Rule

type Rule[T any] interface {
	Run(current *T) (T, error)
	FieldName() string
}

func ArrayGenerator

func ArrayGenerator[T any](fieldName string, n int, gs ...Generator[T]) Rule[T]

ArrayGenerator is a generator that will set a random array of values from the given list of generators to the field.

func RandomFloat

func RandomFloat[T any](fieldName string, start, end float64) Rule[T]

RandomFloat is a generator that will set a random float between the given start and end values to the field.

func RandomInt

func RandomInt[T any](fieldName string, start, end int) Rule[T]

RandomInt is a generator that will set a random integer between the given start and end values to the field.

func RandomPick

func RandomPick[T any, F any](fieldName string, vals ...F) Rule[T]

RandomPick is a generator that will pick a random value from the given list of values and set it to the field.

func RoundRobinGenerator

func RoundRobinGenerator[T any](fieldName string, n int, gs ...Generator[T]) Rule[T]

RoundRobinGenerator is a generator that will iterate over a list of generators in a round robin fashion until the limit is reached or one of the generators is exhausted.

type Runner

type Runner[T any] func(current *T) (T, error)

type Step

type Step[T any] func() T

type StepGenerator

type StepGenerator[T any] struct {
	// contains filtered or unexported fields
}

func (StepGenerator[T]) Add

func (sg StepGenerator[T]) Add(s Step[T]) StepGenerator[T]

func (StepGenerator[T]) Iter

func (s StepGenerator[T]) Iter() Generator[T]

func (StepGenerator[T]) Next

func (s StepGenerator[T]) Next() (T, bool)

Jump to

Keyboard shortcuts

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