gen

package
v0.0.30 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Choice added in v0.0.29

func Choice[T any](arr []T) (T, bool)

Choice 从切片里等概率选择一个元素(空切片返回零值与 false)

func DateRange added in v0.0.29

func DateRange(start, end time.Time) time.Time

DateRange 在给定区间生成随机时间

func FloatRange added in v0.0.29

func FloatRange(min, max float64) float64

FloatRange 生成 [min, max] 的浮点数

func IntN added in v0.0.29

func IntN(max int) int

IntN 生成 [0,n) 的随机整数;n<=0 时返回 0

func IntRange added in v0.0.29

func IntRange(min, max int) int

IntRange 生成 [min, max] 的整数,若 max<min 自动互换

func Letters added in v0.0.29

func Letters(n uint) string

Letters 生成多少个随机字母

func LettersAndNumbers added in v0.0.29

func LettersAndNumbers(n int) string

LettersAndNumbers 生成指定长度的随机字符串(数字 + 大小写字母) 使用 crypto/rand 保证安全级随机。

func NewId

func NewId() (int64, error)

NewId 生成一个新的雪花ID

func NowRecent added in v0.0.29

func NowRecent(dur time.Duration) time.Time

NowRecent 生成目前的近 duration 内的时间

func OneLiner added in v0.0.29

func OneLiner() string

OneLiner 返回一行短文案:优先用 Blurb/Comment 之类,长度可控(大致)

func Paragraph added in v0.0.29

func Paragraph(sentences, wordsPerSentence int) string

Paragraph 用合成句拼装段落

func Sentence added in v0.0.29

func Sentence(words int) string

Sentence 按词数粗控,输出英文句子风格文本

func ShortID added in v0.0.29

func ShortID() string

ShortID 生成可读性强的 22~26 位 base62 短 ID(时间戳 + 随机)

func Shuffle added in v0.0.29

func Shuffle[T any](arr []T)

Shuffle 对切片做原地洗牌

Types

type Article added in v0.0.29

type Article struct {
	Title    string   `json:"title,omitempty" yaml:"title"`
	Author   string   `json:"author,omitempty" yaml:"author"`
	Summary  string   `json:"summary,omitempty" yaml:"summary"`
	Contents []string `json:"contents,omitempty" yaml:"contents"`
}

func NewArticle

func NewArticle(paragraphs, sentenceWords int) Article

NewArticle 生成文章, 输入 段落数量,句子词数

type Order added in v0.0.29

type Order struct {
	ID        string      `json:"id,omitempty" yaml:"id"`
	User      string      `json:"user,omitempty" yaml:"user"`
	Items     []OrderItem `json:"items,omitempty" yaml:"items"`
	Total     float64     `json:"total,omitempty" yaml:"total"`
	Currency  string      `json:"currency,omitempty" yaml:"currency"`
	Status    string      `json:"status,omitempty" yaml:"status"` // created/paid/shipped/finished/refunded
	CreatedAt time.Time   `json:"created_at" yaml:"created_at"`
}

func NewOrder added in v0.0.29

func NewOrder(itemMin, itemMax int) Order

NewOrder 生成模拟订单(含若干条目)

type OrderItem added in v0.0.29

type OrderItem struct {
	ProductID string  `json:"product_id,omitempty"  yaml:"product_id"`
	Name      string  `json:"name,omitempty" yaml:"name"`
	UnitPrice float64 `json:"unit_price,omitempty" yaml:"unit_price"`
	Qty       int     `json:"qty,omitempty" yaml:"qty"`
}

type Person added in v0.0.29

type Person struct {
	Name     string `json:"name,omitempty" yaml:"name"`
	Email    string `json:"email,omitempty" yaml:"email"`
	Phone    string `json:"phone,omitempty" yaml:"phone"`
	Gender   string `json:"gender,omitempty" yaml:"gender"`
	Birthday string `json:"birthday,omitempty" yaml:"birthday"`
	Address  string `json:"address,omitempty" yaml:"address"`
}

func NewPerson added in v0.0.29

func NewPerson() Person

NewPerson 生成一个随机人

type Product added in v0.0.29

type Product struct {
	ID          string    `json:"id,omitempty" yaml:"id"`
	Name        string    `json:"name,omitempty" yaml:"name"`
	Category    string    `json:"category,omitempty" yaml:"category"`
	Description string    `json:"description,omitempty" yaml:"description"`
	Price       float64   `json:"price,omitempty" yaml:"price"`
	Currency    string    `json:"currency,omitempty" yaml:"currency"`
	Stock       int       `json:"stock,omitempty" yaml:"stock"`
	CreatedAt   time.Time `json:"created_at" yaml:"created_at"`
}

func NewProduct added in v0.0.29

func NewProduct() Product

NewProduct 生成模拟商品

Jump to

Keyboard shortcuts

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