From b176592156f486525d651b634e57b754eea84acc Mon Sep 17 00:00:00 2001 From: brianvoe Date: Tue, 27 Feb 2024 11:36:59 -0600 Subject: [PATCH 1/4] faker - if new is 0 generate a crypto random uint64 --- faker.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/faker.go b/faker.go index ac0cf85b..2271eac4 100644 --- a/faker.go +++ b/faker.go @@ -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, From bf67431354c7dd9760f80ba53440aa997f9a8bc3 Mon Sep 17 00:00:00 2001 From: brianvoe Date: Tue, 27 Feb 2024 11:37:09 -0600 Subject: [PATCH 2/4] readme - text update --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e356891a..056ff973 100644 --- a/README.md +++ b/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) From 2d1206a041ccfe29f98446b3353af477e4263107 Mon Sep 17 00:00:00 2001 From: brianvoe Date: Tue, 27 Feb 2024 11:37:44 -0600 Subject: [PATCH 3/4] image - removed image url didnt do anything --- image.go | 42 -------------------------- image_test.go | 20 ------------- person.go | 2 -- person_test.go | 76 +++++++++++++++++++++++------------------------- template_test.go | 1 - 5 files changed, 36 insertions(+), 105 deletions(-) diff --git a/image.go b/image.go index 2c03fbec..9a04bcd6 100644 --- a/image.go +++ b/image.go @@ -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) } @@ -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", diff --git a/image_test.go b/image_test.go index 0c9ec0cd..b9e79f15 100644 --- a/image_test.go +++ b/image_test.go @@ -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)) diff --git a/person.go b/person.go index fbd173da..3eb804c3 100644 --- a/person.go +++ b/person.go @@ -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"` @@ -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), diff --git a/person_test.go b/person_test.go index 9eb935bc..3ff9ebf0 100644 --- a/person_test.go +++ b/person_test.go @@ -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) @@ -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() { @@ -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) @@ -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) { diff --git a/template_test.go b/template_test.go index 448f5e7e..94dcab57 100644 --- a/template_test.go +++ b/template_test.go @@ -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` }}", From 51c0cc0bb772593c1dc6e3850180eb93a0554efb Mon Sep 17 00:00:00 2001 From: brianvoe Date: Tue, 27 Feb 2024 12:01:14 -0600 Subject: [PATCH 4/4] image - removed image url didnt do anything --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 056ff973..836a5e7b 100644 --- a/README.md +++ b/README.md @@ -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