forked from icrowley/fake
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdoc.go
More file actions
45 lines (36 loc) · 1.65 KB
/
doc.go
File metadata and controls
45 lines (36 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
Package fake is a fake data generator, heavily inspired by the forgery and ffaker Ruby gems.
Most data and methods are ported from forgery/ffaker Ruby gems.
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 https://github.com/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 https://github.com/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()
*/
package fake