datafiller

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2023 License: MIT Imports: 3 Imported by: 0

README

datafiller

Build Status GoDoc

A Golang package for filling structs by random data.

Installation

go get github.com/erggo/datafiller

Sample Usage

package main

import (
	"encoding/json"
	"fmt"
	"github.com/erggo/datafiller"
)

type S struct {
	A string
	B struct {
		C string
		D string
		E int
	}
}

func main() {
	i := S{}
	datafiller.Fill(&i)
	b, err := json.Marshal(i)
	if err != nil {
		return
	}
	fmt.Println(string(b))
}

TODO

  • simple types
  • structs
  • slices
  • packages
  • simple tagged structs
  • maps
  • smart tagged struct generation
  • guessing names by names
  • add documentation
  • functions
  • all types
  • add options for filling such as slice length

Documentation

Overview

Package datafiller implements function for randomly filling passed datastructures by mock sample data.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Fill

func Fill(i interface{})

Function Fill takes a pointer to variable of any type and fills the variable by with sample data. It panics if the passed value is not a pointer.

func RandStringBytesMaskImpr

func RandStringBytesMaskImpr(n int) string

会产生大量的丢弃的case,造成重选和浪费。rand.Int63会产生63bit的随机数 如果我们把它分成6份,那么一次就可以产生10个6bit的随机数。这样就减少了浪费

Types

type ArrayMax

type ArrayMax int

func (ArrayMax) AddArg

func (amx ArrayMax) AddArg(f *Filler)

type ArrayMin

type ArrayMin int

func (ArrayMin) AddArg

func (amn ArrayMin) AddArg(f *Filler)

type Filler

type Filler struct {
	Seed int64

	ArrayMin int
	ArrayMax int
	// contains filtered or unexported fields
}

func NewFiller

func NewFiller(args ...FillerArg) *Filler

func (*Filler) Fill

func (f *Filler) Fill(i interface{})

type FillerArg

type FillerArg interface {
	AddArg(*Filler)
}

type Seed

type Seed int64

func (Seed) AddArg

func (sed Seed) AddArg(f *Filler)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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