jaswdr / faker

:rocket: Ultimate fake data generator for Go with zero dependencies
https://pkg.go.dev/github.com/jaswdr/faker
MIT License
570 stars 59 forks source link

New feature for get realistic words according a context #156

Open dhfherna opened 1 year ago

dhfherna commented 1 year ago

Description My solution consists in consuming an API that allows to query a list of words related to a context, for example, for the context of a pastry shop, we can receive the following result: List: pastry, pastrycook, patissier,: bakeshop, confectionary, cakery, pastry chef, pastrymaker, pasteler, bakery, pastrymaking, boulangerie, croissanterie, bakehouse, cake shop, pieshop, doughnutery, baker's, paste Or if you prefer, a single random word from this list: pastrymaker

Are you trying to fix an existing issue?

143

Go Version

$ go version
go version go1.21.3 linux/amd64

Go Tests

$ go test
2023/10/30 11:27:12 Error while requesting https://loremflickr.com/300/200 : request failed
2023/10/30 11:27:13 Error while creating a temp file: temp file creation failed
2023/10/30 11:27:13 Error while requesting https://randomuser.me : request failed
2023/10/30 11:27:13 Error while creating a temp file: temp file creation failed
PASS
ok      github.com/jaswdr/faker 5.128s
ayoubfaouzi commented 1 year ago

Hello @dhfherna

It is probably best not to make network calls to solve this problem.

Making API requests to a third party service can fail or behave unexpectedly.

jaswdr commented 1 year ago

@dhfherna thank you for the PR, although as @LordNoteworthy unfortunately there are many problems that arise when using external services, to start, the machine running the code could not have access to the internet. There is also no guaranteed that the external service will be available, imagine that your code fail because of that, is definitely not a good experience to have. We have similar issues on transient failures in our own tests because we use external services to generate images (which I'm planning to remove in the future).

As alternative, can you move the logic and data to the file itself?