Skip to content
This repository has been archived by the owner on Dec 8, 2022. It is now read-only.

Commit

Permalink
chore: update examples (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
momotaro98 authored Feb 17, 2020
1 parent e58f208 commit 2ed7817
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 60 deletions.
22 changes: 17 additions & 5 deletions CustomFaker.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,32 @@
You can also add your own generator function to your own defined tags. See example below

```go
package main

import (
"fmt"
"reflect"

"github.com/bxcodec/faker/v3"
)

// Gondoruwo ...
type Gondoruwo struct {
Name string
Locatadata int
}

// Sample ...
type Sample struct {
ID int64 `faker:"customIdFaker"`
Gondoruwo Gondoruwo `faker:"gondoruwo"`
Danger string `faker:"danger"`
ID int64 `faker:"customIdFaker"`
Gondoruwo Gondoruwo `faker:"gondoruwo"`
Danger string `faker:"danger"`
}

// CustomGenerator ...
func CustomGenerator() {
faker.AddProvider("customIdFaker", func(v reflect.Value) (interface{}, error) {
return int64(43), nil
return int64(43), nil
})
faker.AddProvider("danger", func(v reflect.Value) (interface{}, error) {
return "danger-ranger", nil
Expand All @@ -31,7 +43,7 @@ func CustomGenerator() {
})
}

func main() {
func main() {
CustomGenerator()
var sample Sample
faker.FakeData(&sample)
Expand Down
80 changes: 40 additions & 40 deletions SingleFakeData.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,76 +5,76 @@
------

```go
faker.Latitude() // => 81.12195
faker.Longitude() // => -84.38158
faker.Latitude() // => 81.12195
faker.Longitude() // => -84.38158
```

### Datetime

---

```go
faker.Unixtime() // => 1197930901
faker.Date() // => 1982-02-27
faker.TimeString() // => 03:10:25
faker.MonthName() // => February
faker.YearString() // => 1994
faker.DayOfWeek() // => Sunday
faker.DayOfMonth() // => 20
faker.Timestamp() // => 1973-06-21 14:50:46
faker.Century() // => IV
faker.Timezone() // => Asia/Jakarta
faker.Timeperiod() // => PM
faker.Unixtime() // => 1197930901
faker.Date() // => 1982-02-27
faker.TimeString() // => 03:10:25
faker.MonthName() // => February
faker.YearString() // => 1994
faker.DayOfWeek() // => Sunday
faker.DayOfMonth() // => 20
faker.Timestamp() // => 1973-06-21 14:50:46
faker.Century() // => IV
faker.Timezone() // => Asia/Jakarta
faker.Timeperiod() // => PM
```

### Internet

---

```go
faker.Email() // => [email protected]
faker.MacAddress() // => cd:65:e1:d4:76:c6
faker.DomainName() // => FWZcaRE.org
faker.URL() // => https://www.oEuqqAY.org/QgqfOhd
faker.Username() // => lVxELHS
faker.IPv4() // => 99.23.42.63
faker.IPv6() // => 975c:fb2c:2133:fbdd:beda:282e:1e0a:ec7d
faker.Password() // => dfJdyHGuVkHBgnHLQQgpINApynzexnRpgIKBpiIjpTP
faker.Email() // => [email protected]
faker.MacAddress() // => cd:65:e1:d4:76:c6
faker.DomainName() // => FWZcaRE.org
faker.URL() // => https://www.oEuqqAY.org/QgqfOhd
faker.Username() // => lVxELHS
faker.IPv4() // => 99.23.42.63
faker.IPv6() // => 975c:fb2c:2133:fbdd:beda:282e:1e0a:ec7d
faker.Password() // => dfJdyHGuVkHBgnHLQQgpINApynzexnRpgIKBpiIjpTP
```

### Words and Sentences

---

```go
faker.Word() // => nesciunt
faker.Sentence() // => Consequatur perferendis voluptatem accusantium.
faker.Paragraph() // => Aut consequatur sit perferendis accusantium voluptatem. Accusantium perferendis consequatur voluptatem sit aut. Aut sit accusantium consequatur voluptatem perferendis. Perferendis voluptatem aut accusantium consequatur sit.
faker.Word() // => nesciunt
faker.Sentence() // => Consequatur perferendis voluptatem accusantium.
faker.Paragraph() // => Aut consequatur sit perferendis accusantium voluptatem. Accusantium perferendis consequatur voluptatem sit aut. Aut sit accusantium consequatur voluptatem perferendis. Perferendis voluptatem aut accusantium consequatur sit.
```

### Payment

---

```go
faker.CCType() // => American Express
faker.CCNumber() // => 373641309057568
faker.Currency() // => USD
faker.AmountWithCurrency() // => USD 49257.100
faker.CCType() // => American Express
faker.CCNumber() // => 373641309057568
faker.Currency() // => USD
faker.AmountWithCurrency() // => USD 49257.100
```

### Person

---

```go
faker.TitleMale() // => Mr.
faker.TitleFemale() // => Mrs.
faker.FirstName() // => Whitney
faker.FirstNameMale() // => Kenny
faker.FirstNameFemale() // => Jana
faker.LastName() // => Rohan
faker.Name() // => Mrs. Casandra Kiehn
faker.TitleMale() // => Mr.
faker.TitleFemale() // => Mrs.
faker.FirstName() // => Whitney
faker.FirstNameMale() // => Kenny
faker.FirstNameFemale() // => Jana
faker.LastName() // => Rohan
faker.Name() // => Mrs. Casandra Kiehn
```


Expand All @@ -84,18 +84,18 @@ faker.Name() // => Mrs. Casandra Kiehn
---

```go
faker.Phonenumber() // -> 201-886-0269
faker.Phonenumber() // -> 201-886-0269
faker.TollFreePhoneNumber() // => (777) 831-964572
faker.E164PhoneNumber() // => +724891571063
faker.E164PhoneNumber() // => +724891571063
```

### UUID

---

```go
faker.UUIDHyphenated() // => 8f8e4463-9560-4a38-9b0c-ef24481e4e27
faker.UUIDDigit() // => 90ea6479fd0e4940af741f0a87596b73
faker.UUIDHyphenated() // => 8f8e4463-9560-4a38-9b0c-ef24481e4e27
faker.UUIDDigit() // => 90ea6479fd0e4940af741f0a87596b73
```

### Unique values
Expand All @@ -107,5 +107,5 @@ faker.SetGenerateUniqueValues(true) // Enable unique data generation on single f
faker.Word()
//...
faker.SetGenerateUniqueValues(false) // Disable unique data generation on single fake data functions
faker.ResetUnique() // Forget all generated unique values
faker.ResetUnique() // Forget all generated unique values
```
40 changes: 28 additions & 12 deletions WithStructTag.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,12 @@ Supported tag:
* unique

```go

package main

import (
"fmt"

"github.com/bxcodec/faker"
"github.com/bxcodec/faker/v3"
)

// SomeStruct ...
Expand All @@ -84,7 +83,7 @@ type SomeStruct struct {
CreditCardNumber string `faker:"cc_number"`
CreditCardType string `faker:"cc_type"`
Email string `faker:"email"`
DomainName string `faker:"domain_name"`
DomainName string `faker:"domain_name"`
IPV4 string `faker:"ipv4"`
IPV6 string `faker:"ipv6"`
Password string `faker:"password"`
Expand Down Expand Up @@ -118,9 +117,9 @@ type SomeStruct struct {
Currency string `faker:"currency"`
Amount float64 `faker:"amount"`
AmountWithCurrency string `faker:"amount_with_currency"`
UUIDHypenated string `faker:"uuid_hyphenated"`
UUID string `faker:"uuid_digit"`
Skip string `faker:"-"`
UUIDHypenated string `faker:"uuid_hyphenated"`
UUID string `faker:"uuid_digit"`
Skip string `faker:"-"`
}

func main() {
Expand Down Expand Up @@ -179,23 +178,24 @@ func main() {
}
*/
}

```

## Length And Boundary

---

You can set length for your random strings also set boundary for your integers.

```go
package main

import (
"fmt"

"github.com/bxcodec/faker"
"github.com/bxcodec/faker/v3"
)

// SomeStruct ...
type SomeStruct struct {
Inta int `faker:"boundary_start=5, boundary_end=10"`
Int8 int8 `faker:"boundary_start=100, boundary_end=1000"`
Expand All @@ -215,8 +215,8 @@ type SomeStruct struct {
MIint map[int]int `faker:"boundary_start=5, boundary_end=10"`
}

func main(){
faker.SetRandomMapAndSliceSize(20) //Random generated map or array size wont exceed 20...
func main() {
faker.SetRandomMapAndSliceSize(20) //Random generated map or array size wont exceed 20...
a := SomeStruct{}
err := faker.FakeData(&a)
if err != nil {
Expand All @@ -226,7 +226,9 @@ func main(){
}

```

Result:

```
{
Inta:7
Expand Down Expand Up @@ -275,17 +277,25 @@ Result:
MIint:map[7:7 5:7 8:8 9:5 6:5]
}
```

## Unique values

```go
package main

import (
"fmt"

"github.com/bxcodec/faker/v3"
)

// SomeStruct ...
type SomeStruct struct {
Word string `faker:"word,unique"`
}

func main() {

for i := 0 ; i < 5 ; i++ { // Generate 5 structs having a unique word
for i := 0; i < 5; i++ { // Generate 5 structs having a unique word
a := SomeStruct{}
err := faker.FakeData(&a)
if err != nil {
Expand All @@ -295,4 +305,10 @@ func main() {
}
faker.ResetUnique() // Forget all generated unique values. Allows to start generating another unrelated dataset.
}
```

Result:

```
{Word:nobis}{Word:recusandae}{Word:praesentium}{Word:doloremque}{Word:non}
```
8 changes: 5 additions & 3 deletions WithoutTag.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
You also can use faker to generate your structs data randomly without any tag. And it will fill the data based on its data-type.

```go

package main

import (
"fmt"

"github.com/bxcodec/faker"
"github.com/bxcodec/faker/v3"
)

// SomeStruct ...
type SomeStruct struct {
Int int
Int8 int8
Expand All @@ -32,18 +32,20 @@ type SomeStruct struct {
SBool []bool
Struct AStruct
}

// AStruct ...
type AStruct struct {
Number int64
Height int64
AnotherStruct BStruct
}

// BStruct ...
type BStruct struct {
Image string
}

func main() {

a := SomeStruct{}
err := faker.FakeData(&a)
if err != nil {
Expand Down

0 comments on commit 2ed7817

Please sign in to comment.