generator

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2020 License: Apache-2.0 Imports: 9 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewFn

func NewFn(opts ...Option) (func() Source, error)

NewFn return data source.

Types

type CsvOpts

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

CsvOpts provides options for CSV generation.

func WithCSV

func WithCSV() CsvOpts

func (CsvOpts) Apply

func (o CsvOpts) Apply() Option

func (CsvOpts) Comma

func (o CsvOpts) Comma(c byte) CsvOpts

Comma sets the comma character. Only ASCII values should be used.

func (CsvOpts) FieldLen

func (o CsvOpts) FieldLen(min, max int) CsvOpts

FieldLen sets the length of each field.

func (CsvOpts) RngSeed

func (o CsvOpts) RngSeed(s int64) CsvOpts

RngSeed will which to a fixed RNG seed to make usage predictable.

func (CsvOpts) Size

func (o CsvOpts) Size(cols, rows int) CsvOpts

Size sets the size of generated CSV.

type Object

type Object struct {
	// Reader will return a reader that will return the number of requested bytes
	// and EOF on all subsequent calls.
	Reader io.Reader

	// A random generated name.
	Name string

	// Corresponding mime type
	ContentType string

	// Size of the object to expect.
	Size int64

	PreFix string
}

type Option

type Option func(o *Options) error

Option provides options for data generation. Use WithXXXX().Apply() to select data types and set options.

func WithPrefixSize

func WithPrefixSize(n int) Option

WithPrefixSize sets prefix size.

func WithRandomSize

func WithRandomSize(b bool) Option

WithRandomSize will randomize the size from 1 byte to the total size set.

func WithSize

func WithSize(n int64) Option

WithSize sets the size of the generated data.

type OptionApplier

type OptionApplier interface {
	Apply() Option
}

OptionApplier allows to abstract generator options.

type Options

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

Options provides options. Use WithXXX functions to set them.

type RandomOpts

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

RandomOpts are the options for the random data source.

func WithRandomData

func WithRandomData() RandomOpts

func (RandomOpts) Apply

func (o RandomOpts) Apply() Option

Apply Random data options.

func (RandomOpts) RngSeed

func (o RandomOpts) RngSeed(s int64) RandomOpts

RngSeed will which to a fixed RNG seed to make usage predictable.

func (RandomOpts) Size

func (o RandomOpts) Size(s int) RandomOpts

Size will set a block size. Data of this size will be repeated until output size has been reached.

type Source

type Source interface {
	// Requesting a new reader will scramble data, so the new reader will not return the same data.
	// Requesting a reader is designed to be as lightweight as possible.
	// Only a single reader can be used concurrently.
	Object() *Object

	// String returns a human readable description of the source.
	String() string
}

func New

func New(opts ...Option) (Source, error)

New return data source.

Jump to

Keyboard shortcuts

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