https://github.com/rulox/faker
A Go library to create Fake Data for your projects
https://github.com/rulox/faker
data dummy dummy-data fake fake-data faker go golang
Last synced: 19 days ago
JSON representation
A Go library to create Fake Data for your projects
- Host: GitHub
- URL: https://github.com/rulox/faker
- Owner: Rulox
- License: mit
- Created: 2018-05-24T23:24:59.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-07-24T20:10:00.000Z (almost 8 years ago)
- Last Synced: 2024-06-21T04:31:49.220Z (almost 2 years ago)
- Topics: data, dummy, dummy-data, fake, fake-data, faker, go, golang
- Language: Go
- Size: 167 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README

# Faker (WIP, do not use this library in production)

[](https://travis-ci.org/Rulox/faker)
[](https://godoc.org/github.com/Rulox/faker)
Faker is a Golang library that generates all type of fake data. Including localized data.
This library is inspired by same libs in other languages like Perl's, ruby's and PHP's Faker.
Faker has been built and tested with Go >= 1.10
## Content
- [Installing](#installing)
- [Usage](#usage)
- [In code](#in-code)
- [Generators](#generators)
- [Misc](doc/misc.md)
- [Address](doc/address.md)
- [Person](doc/person.md)
- [Locales](#locales)
- [Set Locale](#set-your-locale)
- [Examples](examples)
- [FAQ](#faq)
- [License](#license)
### Installing
Just use go get
`go get -u github.com/Rulox/faker`
Or add the library to your project and use `dep ensure`
### Usage
The main struct `generator/Faker` provides all the usability for you in order to create the fake data.
It is necessary to use `faker.NewFaker()` function in order to load default values in some variables.
`Faker` has different type of generators (for Misc data, Addresses, Companies, Phones, etc).
#### In code
```go
f := faker.NewFaker("en_US") // Use en_US locale
f.Misc.RandomInt() // 54
f.Address.Street() // Bedford
```
### Generators
A faker instance has multiple generators. Go to the [documentation](doc) to check all of them.
### Locales
The locales are organized in YAML files called `faker.yml` inside each language folder.
The default locale is `en_US`. A lot of help to create new locales for languages is needed
and the format is so easy that anyone (even if you're not a developer) can supply data
following the format.
#### Set your locale
Setting a locale is really easy. The locale string is passed in the `NewFaker` function.
This function will (among other stuff) load the yaml corresponding to the language code
you choose. Please be careful, use the name of the folder as the locale name `string`.
```go
f := faker.NewFaker("es_ES")
```
You can also change the locale after having your faker initialized
```go
f := faker.NewFaker("en_GB")
// do your stuff here with en_GB set
f.SetLocale("es_ES")
// Spanish time!
```
## FAQ
- Is the data real?
- The data is randomly chosen so no. You may end up with a wrong province/state/zip code combination
- What about gender? Does the library take care of the right combination?
- Not really. There's a plan to add this capability in the future though.
- What about a CLI or console tool?
- Is in the roadmap! Check the project regularly
- How can I Help?
- There's always a missing language or feature. Feel free to open an `issue` or even better, a `pull request`
to help this library growing
## License
This code is free to use under the terms of the MIT license. See LICENSE.md for more information.