fakedata

package
v0.0.0-...-33be302 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2024 License: GPL-3.0 Imports: 17 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultOptions = Options{
	Rand:           NewRand(),
	FloatPrecision: 2,
	NumericBound:   1 << 16,
}

Functions

func Fake

func Fake(ctx context.Context, v cue.Value) (cue.Value, error)

Fake generates fake data for a given cue definition. The returning cue.Value can be decoded into the corresponding Go type. For example, if the cue definition represents a string, the returning value can be decoded into a Go string. Likewise, for maps, we can decode into a map[string]interface{}.

func Generate

func Generate(ctx context.Context, kind Kind, o Options, constraints ...Constraint) interface{}

Generate generates constraints given a kind, options, and values.

func NewRand

func NewRand() *rand.Rand

Types

type Constraint

type Constraint struct {
	Rule  Rule
	Value interface{}
}

Constraint represents a single constraint for the generator.

func (Constraint) String

func (c Constraint) String() string

type Format

type Format int
const (
	FormatEmail Format = iota
	FormatURL
	FormatPhone
	FormatName
	FormatIPv6
	FormatIPv4
	FormatDate
	FormatTime
	FormatTitle
	FormatUUID
)

type Kind

type Kind int
const (
	KindFloat Kind = iota
	KindInt
	KindString
	KindBool
)

func (Kind) String

func (k Kind) String() string

type Options

type Options struct {
	Rand *rand.Rand
	// FloatPrecision is the max number of decimal places to generate for
	// number or float datatypes.
	FloatPrecision int
	// NumericBound is the upper and lower numeric bound for random numbers
	NumericBound int
}

type Output

type Output struct {
	*ast.StructLit
}

Output wraps a StructLit for easy marshalling.

func (*Output) MarshalJSON

func (o *Output) MarshalJSON() ([]byte, error)

type Rule

type Rule int
const (
	RuleLT Rule = iota
	RuleLTE
	RuleGT
	RuleGTE
	RuleEq
	RuleNEq
	RuleOneOf
	RuleFormat // format represents that the string should be in the specified format
)

func (Rule) String

func (r Rule) String() string

Jump to

Keyboard shortcuts

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