generator

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2024 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetExpRandSize added in v0.3.28

func GetExpRandSize(rng *rand.Rand, min, max int64) int64

GetExpRandSize will return an exponential random size from 1 to and including max. Minimum size: 127 bytes, max scale is 256 times smaller than max size. Average size will be max_size * 0.179151.

func MergeObjectPrefixes added in v0.2.0

func MergeObjectPrefixes(o []Objects) []string

MergeObjectPrefixes merges prefixes from several slices of objects.

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

WithCSV returns default CSV Opts

func (CsvOpts) Apply

func (o CsvOpts) Apply() Option

Apply applies all the opts for CSVOpts

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.ReadSeeker

	// A random generated name.
	Name string

	// Corresponding mime type
	ContentType string

	Prefix string

	VersionID string

	// Size of the object to expect.
	Size int64
}

type Objects added in v0.2.0

type Objects []Object

Objects is a slice of objects.

func (Objects) Prefixes added in v0.2.0

func (o Objects) Prefixes() []string

Prefixes returns all prefixes.

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 WithCustomPrefix added in v0.3.46

func WithCustomPrefix(prefix string) Option

WithCustomPrefix adds custom prefix under bucket where all warp content is created.

func WithMinMaxSize added in v0.6.6

func WithMinMaxSize(min, max int64) Option

WithMinMaxSize sets the min and max size of the generated data.

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

	// Prefix returns the prefix if any.
	Prefix() 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