Skip to content

Latest commit

 

History

History
68 lines (52 loc) · 2.69 KB

README.md

File metadata and controls

68 lines (52 loc) · 2.69 KB

Fake

Build Status GoDoc License Go Report Card

Fake is a fake data generator for Go (Golang), heavily inspired by the forgery and ffaker Ruby gems. This particular branch is a fork from icrowley with improvements merged from the community.

About

Most data and methods are ported from forgery/ffaker Ruby gems. For the list of available methods, please look at GoDoc.

Currently, English and Russian are available. English is the default. If the selected language does not implement the required data, then English will be returned as a fallback. This may be disabled by calling EnFallback(false).

Fake stores the raw data in line-delimited files under data/, which is subdivided by language. By default, fake uses a gzip'd representation of the filesystem generated by mjibson/esc. Embedding the data removes external file dependencies during runtime, and compression gives a small space gain. Decompressed files are cached after first access.

If the sample data is changed or new data is added, data.go must be regenerated. If you are using Go >=1.4, then a simple go generate will handle it. Otherwise, you must get mjibson/esc and run esc -o data.go -pkg fake data.

Fake can load the files directly from the filesystem by calling UseExternalData(true).

Examples

Basic data:

name := fake.FirstName()
fullname := fake.FullName()
product := fake.Product()

Select non-English language:

err := fake.SetLang("ru")
if err != nil {
  panic(err)
}
password := fake.SimplePassword()

Remove English fallback:

err := fake.SetLang("ru")
if err != nil {
  panic(err)
}
fake.EnFallback(false)
password := fake.Paragraph() // returns a blank string because Paragraph() is not implemented in Russian

Use external data:

fake.UseExternalData(true)
password := fake.Paragraph()

Credit

The common English wordlist located in data/en/words is from Wiktionary, licensed under the Creative Commons Attribution-ShareAlike License