Skip to content

Commit dbc0519

Browse files
committed
Merge branch 'develop'
2 parents c450282 + 50705d5 commit dbc0519

19 files changed

+627
-115
lines changed

README.md

Lines changed: 39 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
![alt text](https://raw.githubusercontent.com/brianvoe/gofakeit/master/logo.png)
22

3-
# Gofakeit [![Go Report Card](https://goreportcard.com/badge/github.com/brianvoe/gofakeit)](https://goreportcard.com/report/github.com/brianvoe/gofakeit) ![Test](https://github.com/brianvoe/gofakeit/workflows/Test/badge.svg?branch=master) [![codecov.io](https://codecov.io/github/brianvoe/gofakeit/branch/master/graph/badge.svg)](https://codecov.io/github/brianvoe/gofakeit) [![GoDoc](https://godoc.org/github.com/brianvoe/gofakeit/v6?status.svg)](https://godoc.org/github.com/brianvoe/gofakeit/v6) [![license](http://img.shields.io/badge/license-MIT-green.svg?style=flat)](https://raw.githubusercontent.com/brianvoe/gofakeit/master/LICENSE.txt)
3+
# Gofakeit [![Go Report Card](https://goreportcard.com/badge/github.com/brianvoe/gofakeit)](https://goreportcard.com/report/github.com/brianvoe/gofakeit) ![Test](https://github.com/brianvoe/gofakeit/workflows/Test/badge.svg?branch=master) [![GoDoc](https://godoc.org/github.com/brianvoe/gofakeit/v6?status.svg)](https://godoc.org/github.com/brianvoe/gofakeit/v6) [![license](http://img.shields.io/badge/license-MIT-green.svg?style=flat)](https://raw.githubusercontent.com/brianvoe/gofakeit/master/LICENSE.txt)
44

55
Random data generator written in go
66

@@ -10,7 +10,7 @@ Random data generator written in go
1010

1111
## Features
1212

13-
- [260+ Functions!!!](#functions)
13+
- [310+ Functions!!!](#functions)
1414
- [Random Sources](#random-sources)
1515
- [Global Rand](#global-rand-set)
1616
- [Struct Generator](#struct)
@@ -24,7 +24,7 @@ Random data generator written in go
2424

2525
## Contributors
2626

27-
Thanks to everyone who has contributed to Gofakeit!
27+
Thank you to all our Gofakeit contributors!
2828

2929
<a href="https://github.com/brianvoe/gofakeit/graphs/contributors">
3030
<img src="https://contrib.rocks/image?repo=brianvoe/gofakeit" />
@@ -185,14 +185,14 @@ For example, this is useful when it is not possible to modify the struct that yo
185185
// or just return a static value
186186
type CustomString string
187187

188-
func (c *CustomString) Fake(faker *gofakeit.Faker) any {
188+
func (c *CustomString) Fake(faker *gofakeit.Faker) (any, error) {
189189
return CustomString("my custom string")
190190
}
191191

192192
// Imagine a CustomTime type that is needed to support a custom JSON Marshaler
193193
type CustomTime time.Time
194194

195-
func (c *CustomTime) Fake(faker *gofakeit.Faker) any {
195+
func (c *CustomTime) Fake(faker *gofakeit.Faker) (any, error) {
196196
return CustomTime(time.Now())
197197
}
198198

@@ -266,8 +266,6 @@ fmt.Printf("%s", f.FriendName) // bill
266266
fmt.Printf("%s", f.JumbleWord) // loredlowlh
267267
```
268268

269-
270-
271269
## Templates
272270

273271
Generate custom outputs using golang's template engine [https://pkg.go.dev/text/template](https://pkg.go.dev/text/template).
@@ -280,7 +278,7 @@ Additional Available Functions
280278
- ToLower(s string) string // Make string lower case
281279
- ToString(s any) // Convert to string
282280
- ToDate(s string) time.Time // Convert string to date
283-
- SpliceAny(args ...any) []any // Build a slice of interfaces, used with Weighted
281+
- SpliceAny(args ...any) []any // Build a slice of anys, used with Weighted
284282
- SpliceString(args ...string) []string // Build a slice of strings, used with Teams and RandomString
285283
- SpliceUInt(args ...uint) []uint // Build a slice of uint, used with Dice and RandomUint
286284
- SpliceInt(args ...int) []int // Build a slice of int, used with RandomInt
@@ -355,7 +353,7 @@ All functions also exist as methods on the Faker struct
355353

356354
### File
357355

358-
Passing `nil` to `CSV`, `JSON` or `XML` will auto generate data using a random set of generators.
356+
Passing `nil` to `CSV`, `JSON` or `XML` will auto generate data using default values.
359357

360358
```go
361359
CSV(co *CSVOptions) ([]byte, error)
@@ -365,6 +363,27 @@ FileExtension() string
365363
FileMimeType() string
366364
```
367365

366+
### Template
367+
368+
Passing `nil` will auto generate data using default values.
369+
370+
```go
371+
Template(co *TemplateOptions) (string, error)
372+
Markdown(co *MarkdownOptions) (string, error)
373+
EmailText(co *EmailOptions) (string, error)
374+
FixedWidth(co *FixedWidthOptions) (string, error)
375+
```
376+
377+
### Product
378+
379+
```go
380+
Product() *ProductInfo
381+
ProductName() string
382+
ProductDescription() string
383+
ProductCategory() string
384+
ProductFeature() string
385+
ProductMaterial() string
386+
```
368387

369388
### Person
370389

@@ -457,9 +476,8 @@ CarTransmissionType() string
457476

458477
### Words
459478

460-
#### Noun
461-
462479
```go
480+
// Nouns
463481
Noun() string
464482
NounCommon() string
465483
NounConcrete() string
@@ -469,20 +487,14 @@ NounCollectiveAnimal() string
469487
NounCollectiveThing() string
470488
NounCountable() string
471489
NounUncountable() string
472-
```
473-
474-
#### Verb
475490

476-
```go
491+
// Verbs
477492
Verb() string
478493
VerbAction() string
479494
VerbLinking() string
480495
VerbHelping() string
481-
```
482496

483-
#### Adverb
484-
485-
```go
497+
// Adverbs
486498
Adverb() string
487499
AdverbManner() string
488500
AdverbDegree() string
@@ -491,20 +503,14 @@ AdverbTimeDefinite() string
491503
AdverbTimeIndefinite() string
492504
AdverbFrequencyDefinite() string
493505
AdverbFrequencyIndefinite() string
494-
```
495-
496-
#### Proposition
497506

498-
```go
507+
// Propositions
499508
Preposition() string
500509
PrepositionSimple() string
501510
PrepositionDouble() string
502511
PrepositionCompound() string
503-
```
504-
505-
#### Adjective
506512

507-
```go
513+
// Adjectives
508514
Adjective() string
509515
AdjectiveDescriptive() string
510516
AdjectiveQuantitative() string
@@ -513,11 +519,8 @@ AdjectiveDemonstrative() string
513519
AdjectivePossessive() string
514520
AdjectiveInterrogative() string
515521
AdjectiveIndefinite() string
516-
```
517522

518-
#### Pronoun
519-
520-
```go
523+
// Pronouns
521524
Pronoun() string
522525
PronounPersonal() string
523526
PronounObject() string
@@ -526,29 +529,20 @@ PronounReflective() string
526529
PronounDemonstrative() string
527530
PronounInterrogative() string
528531
PronounRelative() string
529-
```
530532

531-
#### Connective
532-
533-
```go
533+
// Connectives
534534
Connective() string
535535
ConnectiveTime() string
536536
ConnectiveComparative() string
537537
ConnectiveComplaint() string
538538
ConnectiveListing() string
539539
ConnectiveCasual() string
540540
ConnectiveExamplify() string
541-
```
542-
543-
#### Word
544541

545-
```go
542+
// Words
546543
Word() string
547-
```
548-
549-
#### Sentences
550544

551-
```go
545+
// Sentences
552546
Sentence(wordCount int) string
553547
Paragraph(paragraphCount int, sentenceCount int, wordCount int, separator string) string
554548
LoremIpsumWord() string
@@ -576,7 +570,7 @@ Dessert() string
576570
```go
577571
Bool() bool
578572
UUID() string
579-
Weighted(options []any, weights []float32)
573+
Weighted(options []any, weights []float32) (any, error)
580574
FlipACoin() string
581575
RandomMapKey(mapI any) any
582576
ShuffleAnySlice(v any)
@@ -852,14 +846,5 @@ ErrorRuntime() error
852846
### School
853847

854848
```go
855-
school() string
849+
School() string
856850
```
857-
858-
## Template
859-
860-
```go
861-
Template(co *TemplateOptions) (string, error) // Generates custom documents
862-
Markdown(co *MarkdownOptions) (string, error) // Generates markdown documents
863-
EmailText(co *EmailOptions) (string, error) // Generates email documents
864-
FixedWidth(co *FixedWidthOptions) (string, error) // Generates fixed width documents
865-
```

address.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ func addAddressLookup() {
209209
latitude: "23.058758",
210210
longitude: "89.022594"
211211
}`,
212-
Output: "map[string]interface",
212+
Output: "map[string]any",
213213
ContentType: "application/json",
214214
Generate: func(r *rand.Rand, m *MapParams, info *Info) (any, error) {
215215
return address(r), nil

car.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func addCarLookup() {
7676
Display: "Car",
7777
Category: "car",
7878
Description: "Random car set of data",
79-
Output: "map[string]interface",
79+
Output: "map[string]any",
8080
ContentType: "application/json",
8181
Example: `{type: "Passenger car mini", fuel: "Gasoline", transmission: "Automatic", brand: "Fiat", model: "Freestyle Fwd", year: "1972"}`,
8282
Generate: func(r *rand.Rand, m *MapParams, info *Info) (any, error) {

csv.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,19 @@ func addFileCSVLookup() {
138138
Output: "[]byte",
139139
ContentType: "text/csv",
140140
Params: []Param{
141+
{Field: "delimiter", Display: "Delimiter", Type: "string", Default: ",", Description: "Separator in between row values"},
141142
{Field: "rowcount", Display: "Row Count", Type: "int", Default: "100", Description: "Number of rows"},
142143
{Field: "fields", Display: "Fields", Type: "[]Field", Description: "Fields containing key name and function"},
143-
{Field: "delimiter", Display: "Delimiter", Type: "string", Default: ",", Description: "Separator in between row values"},
144144
},
145145
Generate: func(r *rand.Rand, m *MapParams, info *Info) (any, error) {
146146
co := CSVOptions{}
147147

148+
delimiter, err := info.GetString(m, "delimiter")
149+
if err != nil {
150+
return nil, err
151+
}
152+
co.Delimiter = delimiter
153+
148154
rowcount, err := info.GetInt(m, "rowcount")
149155
if err != nil {
150156
return nil, err
@@ -169,12 +175,6 @@ func addFileCSVLookup() {
169175
}
170176
}
171177

172-
delimiter, err := info.GetString(m, "delimiter")
173-
if err != nil {
174-
return nil, err
175-
}
176-
co.Delimiter = delimiter
177-
178178
f := &Faker{Rand: r}
179179
csvOut, err := csvFunc(f, &co)
180180
if err != nil {

data/data.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ var Data = map[string]map[string][]string{
3131
"book": Books,
3232
"movie": Movies,
3333
"school": School,
34+
"product": Product,
3435
}
3536

3637
func List() map[string][]string {

data/product.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package data
2+
3+
var Product = map[string][]string{
4+
"category": {
5+
"electronics", "clothing", "home appliances", "furniture",
6+
"automotive parts", "beauty and personal care", "books", "sports equipment",
7+
"toys and games", "outdoor gear", "pet supplies", "kitchenware",
8+
"health and wellness", "tools and hardware", "office supplies",
9+
"baby products", "jewelry", "home decor", "musical instruments",
10+
"fitness equipment", "mobile phones", "computer accessories", "cameras and photography",
11+
"gardening supplies", "bedding and linens", "food and groceries", "party supplies",
12+
"craft and diy supplies", "camping gear", "watches", "luggage and travel accessories",
13+
"board games", "art supplies", "stationery", "bath and shower products",
14+
"sunglasses", "educational toys", "headphones and earbuds", "sneakers and athletic shoes",
15+
"coffee and tea products", "bicycles and accessories", "cookware", "cosmetics",
16+
"home improvement", "pet food", "laptop bags and cases", "home security systems",
17+
"musical accessories", "skincare products", "smart home devices",
18+
},
19+
20+
"adjective": {
21+
"bold", "swift", "pure", "smart", "fresh",
22+
"cool", "sharp", "zen", "bright", "quick",
23+
"robust", "sleek", "versatile", "innovative", "compact",
24+
"luxe", "modular", "precision", "stream",
25+
},
26+
27+
"name": {
28+
"phone", "laptop", "tablet", "watch", "camera",
29+
"headphones", "speaker", "drone", "car", "bike",
30+
"appliance", "gadget", "tool", "toy", "game",
31+
"computer", "console", "smartwatch", "fitness tracker", "smart home device",
32+
"robot", "router", "television", "smart speaker", "vr headset",
33+
"earbuds", "printer", "mouse", "keyboard", "monitor",
34+
"microwave", "blender", "vacuum", "fan", "toaster",
35+
"clock", "lamp", "shaver", "scale", "thermometer",
36+
"fridge", "oven", "mixer", "iron", "hair dryer",
37+
"fan", "scale", "thermostat", "router", "lightbulb",
38+
},
39+
40+
"feature": {
41+
"wireless", "smart", "eco-friendly", "advanced", "compact",
42+
"high-performance", "energy-efficient", "portable", "durable", "stylish",
43+
"touchscreen", "water-resistant", "noise-canceling", "voice-controlled", "ultra-lightweight",
44+
"multi-functional", "user-friendly", "fast-charging", "biometric", "gps-enabled",
45+
},
46+
47+
"material": {
48+
"titanium", "carbon", "alloy", "bamboo", "leather",
49+
"glass", "ceramic", "aluminum", "stainless", "wood",
50+
"plastic", "rubber", "silicon", "fabric", "paper",
51+
"gold", "silver", "brass", "copper", "bronze",
52+
"chrome", "marble", "granite", "porcelain", "plexiglass",
53+
"quartz", "felt", "suede",
54+
},
55+
56+
"suffix": {
57+
"tech", "pro", "x", "plus", "elite",
58+
"spark", "nexus", "nova", "fusion", "sync",
59+
"edge", "boost", "max", "link", "prime",
60+
"zoom", "pulse", "dash", "connect", "blaze",
61+
"quantum", "spark", "vertex", "core", "flux",
62+
"turbo", "shift", "wave", "matrix",
63+
},
64+
}

helpers_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ func TestAnyToStringEdgeCases(t *testing.T) {
263263

264264
// Test with a struct containing a nil interface field
265265
type nilInterfaceFieldStruct struct {
266-
Data interface{}
266+
Data any
267267
}
268268
nilInterfaceStruct := nilInterfaceFieldStruct{}
269269
want = `{"Data":null}`

0 commit comments

Comments
 (0)