faker

package module
v0.0.0-...-05b7847 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 24, 2018 License: MIT Imports: 4 Imported by: 2

README

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

quality Build Status GoDoc

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

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
    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 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.

	f := faker.NewFaker("es_ES")

You can also change the locale after having your faker initialized

	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.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Faker

type Faker struct {
	// If the generator should return always unique values. Note that this will have some limitations.
	// If you want more data than the available unique data, the Generator won't fail but it'll print a warning to
	// let you know it was impossible to generate unique data for you.
	Unique bool

	// Misc data generator
	Misc generator.MiscGenerator
	// Address data generator
	Address generator.AddressGenerator
	// Person data generator
	Person generator.PersonGenerator
	// Phone data generator
	Phone generator.PhoneGenerator
	// contains filtered or unexported fields
}

Base struct for all generators.

func NewFaker

func NewFaker(l string) (f Faker)

Return a new Faker to start working with. It is necessary to use this 'constructor' in order to initialize some variables and to run the default locale `en_US`

func (*Faker) Clear

func (f *Faker) Clear()

Clear the unique values storage so values can be repeated again

func (*Faker) SetLocale

func (f *Faker) SetLocale(l string) error

Set locale for all the generators

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL