Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
brianvoe committed Feb 27, 2024
2 parents 70b796c + 51c0cc0 commit c4255fd
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 107 deletions.
3 changes: 1 addition & 2 deletions README.md
@@ -1,4 +1,4 @@
![alt text](https://raw.githubusercontent.com/brianvoe/gofakeit/master/logo.png)
![Gofakeit](https://raw.githubusercontent.com/brianvoe/gofakeit/master/logo.png)

# 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/v7?status.svg)](https://godoc.org/github.com/brianvoe/gofakeit/v7) [![license](http://img.shields.io/badge/license-MIT-green.svg?style=flat)](https://raw.githubusercontent.com/brianvoe/gofakeit/master/LICENSE.txt)

Expand Down Expand Up @@ -600,7 +600,6 @@ NiceColors() string
### Images

```go
ImageURL(width int, height int) string
Image(width int, height int) *img.RGBA
ImageJpeg(width int, height int) []byte
ImagePng(width int, height int) []byte
Expand Down
6 changes: 6 additions & 0 deletions faker.go
Expand Up @@ -24,6 +24,12 @@ type Faker struct {
// New creates and returns a new Faker struct seeded with a given seed
// using the PCG algorithm in lock mode for thread safety
func New(seed uint64) *Faker {
// If seed is 0, use a random crypto seed
if seed == 0 {
faker := NewFaker(source.NewCrypto(), false)
seed = faker.Uint64()
}

return &Faker{
Rand: rand.NewPCG(seed, seed),
Locked: true,
Expand Down
42 changes: 0 additions & 42 deletions image.go
Expand Up @@ -7,19 +7,8 @@ import (
imgCol "image/color"
"image/jpeg"
"image/png"
"strconv"
)

// ImageURL will generate a random Image Based Upon Height And Width. https://picsum.photos/
func ImageURL(width int, height int) string { return imageURL(GlobalFaker, width, height) }

// ImageURL will generate a random Image Based Upon Height And Width. https://picsum.photos/
func (f *Faker) ImageURL(width int, height int) string { return imageURL(f, width, height) }

func imageURL(f *Faker, width int, height int) string {
return "https://picsum.photos/" + strconv.Itoa(width) + "/" + strconv.Itoa(height)
}

// Image generates a random rgba image
func Image(width int, height int) *img.RGBA { return image(GlobalFaker, width, height) }

Expand Down Expand Up @@ -67,37 +56,6 @@ func imagePng(f *Faker, width int, height int) []byte {
}

func addImageLookup() {
AddFuncLookup("imageurl", Info{
Display: "Image URL",
Category: "image",
Description: "Web address pointing to an image file that can be accessed and displayed online",
Example: "https://picsum.photos/500/500",
Output: "string",
Params: []Param{
{Field: "width", Display: "Width", Type: "int", Default: "500", Description: "Image width in px"},
{Field: "height", Display: "Height", Type: "int", Default: "500", Description: "Image height in px"},
},
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
width, err := info.GetInt(m, "width")
if err != nil {
return nil, err
}
if width < 10 || width >= 1000 {
return nil, errors.New("invalid image width, must be greater than 10, less than 1000")
}

height, err := info.GetInt(m, "height")
if err != nil {
return nil, err
}
if height < 10 || height >= 1000 {
return nil, errors.New("invalid image height, must be greater than 10, less than 1000")
}

return imageURL(f, width, height), nil
},
})

AddFuncLookup("imagejpeg", Info{
Display: "Image JPEG",
Category: "image",
Expand Down
20 changes: 0 additions & 20 deletions image_test.go
Expand Up @@ -5,26 +5,6 @@ import (
"testing"
)

func ExampleImageURL() {
Seed(11)
fmt.Println(ImageURL(640, 480))

// Output: https://picsum.photos/640/480
}

func ExampleFaker_ImageURL() {
f := New(11)
fmt.Println(f.ImageURL(640, 480))

// Output: https://picsum.photos/640/480
}

func BenchmarkImageURL(b *testing.B) {
for i := 0; i < b.N; i++ {
ImageURL(640, 480)
}
}

func ExampleImage() {
Seed(11)
fmt.Println(Image(1, 1))
Expand Down
2 changes: 0 additions & 2 deletions person.go
Expand Up @@ -12,7 +12,6 @@ type PersonInfo struct {
LastName string `json:"last_name" xml:"last_name"`
Gender string `json:"gender" xml:"gender"`
SSN string `json:"ssn" xml:"ssn"`
Image string `json:"image" xml:"image"`
Hobby string `json:"hobby" xml:"hobby"`
Job *JobInfo `json:"job" xml:"job"`
Address *AddressInfo `json:"address" xml:"address"`
Expand All @@ -32,7 +31,6 @@ func person(f *Faker) *PersonInfo {
LastName: lastName(f),
Gender: gender(f),
SSN: ssn(f),
Image: imageURL(f, number(f, 100, 500), number(f, 100, 500)),
Hobby: hobby(f),
Job: job(f),
Address: address(f),
Expand Down
76 changes: 36 additions & 40 deletions person_test.go
Expand Up @@ -197,7 +197,6 @@ func ExamplePerson() {
fmt.Println(person.LastName)
fmt.Println(person.Gender)
fmt.Println(person.SSN)
fmt.Println(person.Image)
fmt.Println(person.Hobby)

fmt.Println(job.Company)
Expand Down Expand Up @@ -226,26 +225,25 @@ func ExamplePerson() {
// Stiedemann
// male
// 280254464
// https://picsum.photos/311/192
// Sea glass collecting
// Mango Transit
// Supervisor
// National
// Solutions
// 999 West Lanebury, Lincoln, Kansas 93050
// 999 West Lanebury
// Lincoln
// Kansas
// 93050
// Uganda
// -0.729058
// -53.873895
// 6268940591
// hopeprohaska@metz.io
// Sailing
// DataLogix
// Planner
// Human
// Usability
// 679 Underpassborough, Omaha, Massachusetts 37930
// 679 Underpassborough
// Omaha
// Massachusetts
// 37930
// North Macedonia
// -0.877085
// 83.264578
// 4102689405
// verdabrakus@mayert.name
// American Express
// 4570938757201747
// 11/27
// 205
// 562570938760
// 04/25
// 906
}

func ExampleFaker_Person() {
Expand All @@ -260,7 +258,6 @@ func ExampleFaker_Person() {
fmt.Println(person.LastName)
fmt.Println(person.Gender)
fmt.Println(person.SSN)
fmt.Println(person.Image)
fmt.Println(person.Hobby)

fmt.Println(job.Company)
Expand Down Expand Up @@ -289,26 +286,25 @@ func ExampleFaker_Person() {
// Stiedemann
// male
// 280254464
// https://picsum.photos/311/192
// Sea glass collecting
// Mango Transit
// Supervisor
// National
// Solutions
// 999 West Lanebury, Lincoln, Kansas 93050
// 999 West Lanebury
// Lincoln
// Kansas
// 93050
// Uganda
// -0.729058
// -53.873895
// 6268940591
// hopeprohaska@metz.io
// Sailing
// DataLogix
// Planner
// Human
// Usability
// 679 Underpassborough, Omaha, Massachusetts 37930
// 679 Underpassborough
// Omaha
// Massachusetts
// 37930
// North Macedonia
// -0.877085
// 83.264578
// 4102689405
// verdabrakus@mayert.name
// American Express
// 4570938757201747
// 11/27
// 205
// 562570938760
// 04/25
// 906
}

func BenchmarkPerson(b *testing.B) {
Expand Down
1 change: 0 additions & 1 deletion template_test.go
Expand Up @@ -103,7 +103,6 @@ func TestTemplate_misc(t *testing.T) {
"Number": "{{Number 1 42 }}",
"Price": "{{Price 1 100 }}",
"Regex": "{{Regex `[abcdef]{5}` }}",
"ImageURL": "{{ImageURL 640 480 }}",
"DigitN": "{{DigitN 10 }}",
"LoremIpsumParagraph": "{{LoremIpsumParagraph 3 5 12 `\n` }}",
"Paragraph": "{{Paragraph 3 5 12 `\n` }}",
Expand Down

0 comments on commit c4255fd

Please sign in to comment.