Documentation
¶
Overview ¶
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()
Index ¶
- Variables
- func Amount() float32
- func Between(from, to int) int
- func Birthdate(age int) time.Time
- func Bool() bool
- func Brand() string
- func Character() string
- func Characters() string
- func CharactersN(n int) string
- func Choose(v ...interface{}) interface{}
- func City() string
- func Color() string
- func Company() string
- func Continent() string
- func Country() string
- func CreditCardNum(vendor string) string
- func CreditCardType() string
- func Currency() string
- func CurrencyCode() string
- func Day() int
- func Digits() string
- func DigitsN(n int) string
- func Dir(useLocal bool, name string) http.FileSystem
- func DomainName() string
- func DomainZone() string
- func Education() string
- func EmailAddress() string
- func EmailBody() string
- func EmailSubject() string
- func EnFallback(flag bool)
- func Ethnicities(n int) (a []string)
- func Ethnicity() string
- func FS(useLocal bool) http.FileSystem
- func FSByte(useLocal bool, name string) ([]byte, error)
- func FSMustByte(useLocal bool, name string) []byte
- func FSMustString(useLocal bool, name string) string
- func FSString(useLocal bool, name string) (string, error)
- func FemaleFirstName() string
- func FemaleFullName() string
- func FemaleFullNameWithPrefix() string
- func FemaleFullNameWithSuffix() string
- func FemaleLastName() string
- func FemalePatronymic() string
- func FirstName() string
- func FullName() string
- func FullNameWithPrefix() string
- func FullNameWithSuffix() string
- func Gender() string
- func GenderAbbrev() string
- func GetLangs() []string
- func HexColor() string
- func HexColorShort() string
- func IPv4() string
- func IPv6() string
- func Industry() string
- func JobTitle() string
- func Language() string
- func LastName() string
- func LatitudeDegrees() int
- func LatitudeDirection() string
- func LatitudeMinutes() int
- func LatitudeSeconds() int
- func Latitute() float32
- func Longitude() float32
- func LongitudeDegrees() int
- func LongitudeDirection() string
- func LongitudeMinutes() int
- func LongitudeSeconds() int
- func MaleFirstName() string
- func MaleFullName() string
- func MaleFullNameWithPrefix() string
- func MaleFullNameWithSuffix() string
- func MaleLastName() string
- func MalePatronymic() string
- func MaritalStatus() string
- func Model() string
- func Month() string
- func MonthNum() int
- func MonthShort() string
- func Paragraph() string
- func Paragraphs() string
- func ParagraphsN(n int) string
- func Password(atLeast, atMost int, allowUpper, allowNumeric, allowSpecial bool) string
- func Patronymic() string
- func Phone() string
- func Product() string
- func ProductName() string
- func Question() string
- func Religion() string
- func Religions(n int) (a []string)
- func Seed(seed int64)
- func Sentence() string
- func Sentences() string
- func SentencesN(n int) string
- func SetLang(newLang string) error
- func SexualOrientation() string
- func SimplePassword() string
- func State() string
- func StateAbbrev() string
- func Street() string
- func StreetAddress() string
- func Time(from, to time.Time) time.Time
- func Title() string
- func TopLevelDomain() string
- func Toss() int
- func UseExternalData(flag bool)
- func UserAgent() string
- func UserName() string
- func Version() string
- func WeekDay() string
- func WeekDayShort() string
- func WeekdayNum() int
- func Word() string
- func Words() string
- func WordsN(n int) string
- func WordsNUnique(n int) []string
- func Year(from, to int) int
- func Zip() string
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNoLanguage indicates that the given language is not available ErrNoLanguage = errors.New("Language unavailable") // ErrNoSamples indicates that there are no samples for the given language ErrNoSamples = errors.New("No samples found for given language") )
Functions ¶
func Characters ¶
func Characters() string
Characters generates from 1 to 5 characters in the given language
func CharactersN ¶
CharactersN generates n random characters in the given language
func Choose ¶
func Choose(v ...interface{}) interface{}
Choose selects a random item from the given set
func CreditCardNum ¶
CreditCardNum generated credit card number according to the vendor's card number rules. Currently supports amex, discover, mastercard, and visa.
func CreditCardType ¶
func CreditCardType() string
CreditCardType returns one of the following credit values: VISA, MasterCard, American Express and Discover
func Dir ¶
func Dir(useLocal bool, name string) http.FileSystem
Dir returns a http.Filesystem for the embedded assets on a given prefix dir. If useLocal is true, the filesystem's contents are instead used.
func EnFallback ¶
func EnFallback(flag bool)
EnFallback sets the flag that allows fake to fallback to englsh samples if the ones for the used languaged are not available
func Ethnicities ¶
func FS ¶
func FS(useLocal bool) http.FileSystem
FS returns a http.Filesystem for the embedded assets. If useLocal is true, the filesystem's contents are instead used.
func FSByte ¶
FSByte returns the named file from the embedded assets. If useLocal is true, the filesystem's contents are instead used.
func FSMustByte ¶
FSMustByte is the same as FSByte, but panics if name is not present.
func FSMustString ¶
FSMustString is the string version of FSMustByte.
func FemaleFullName ¶
func FemaleFullName() string
FemaleFullName generates female full name it can occasionally include prefix or suffix
func FemaleFullNameWithPrefix ¶
func FemaleFullNameWithPrefix() string
FemaleFullNameWithPrefix generates prefixed female full name if prefixes for the given language are available
func FemaleFullNameWithSuffix ¶
func FemaleFullNameWithSuffix() string
FemaleFullNameWithSuffix generates suffixed female full name if suffixes for the given language are available
func FullName ¶
func FullName() string
FullName generates full name it can occasionally include prefix or suffix
func FullNameWithPrefix ¶
func FullNameWithPrefix() string
FullNameWithPrefix generates prefixed full name if prefixes for the given language are available
func FullNameWithSuffix ¶
func FullNameWithSuffix() string
FullNameWithSuffix generates suffixed full name if suffixes for the given language are available
func GenderAbbrev ¶
func GenderAbbrev() string
GenderAbbrev returns first downcased letter of the random gender
func LatitudeDegrees ¶
func LatitudeDegrees() int
LatitudeDegrees generates latitude degrees (from -180 to 180)
func LatitudeDirection ¶
func LatitudeDirection() string
LatitudeDirection generates latitude direction (N(orth) o S(outh))
func LatitudeMinutes ¶
func LatitudeMinutes() int
LatitudeMinutes generates latitude minutes (from 0 to 60)
func LatitudeSeconds ¶
func LatitudeSeconds() int
LatitudeSeconds generates latitude seconds (from 0 to 60)
func LongitudeDegrees ¶
func LongitudeDegrees() int
LongitudeDegrees generates longitude degrees (from -180 to 180)
func LongitudeDirection ¶
func LongitudeDirection() string
LongitudeDirection generates (W(est) or E(ast))
func MaleFullName ¶
func MaleFullName() string
MaleFullName generates male full name it can occasionally include prefix or suffix
func MaleFullNameWithPrefix ¶
func MaleFullNameWithPrefix() string
MaleFullNameWithPrefix generates prefixed male full name if prefixes for the given language are available
func MaleFullNameWithSuffix ¶
func MaleFullNameWithSuffix() string
MaleFullNameWithSuffix generates suffixed male full name if suffixes for the given language are available
func Model ¶
func Model() string
Model generates model name that consists of letters and digits, optionally with a hyphen between them
func Password ¶
Password generates password with the length from atLeast to atMOst charachers, allow* parameters specify whether corresponding symbols can be used
func Phone ¶
func Phone() string
Phone generates random phone number using one of the formats format specified in phone_format file
func Seed ¶
func Seed(seed int64)
Seed uses the provided seed value to initialize the internal PRNG to a deterministic state.
func SetLang ¶
SetLang sets the language in which the data should be generated, and returns ErrNoLanguage if lang doesn't exist
func SexualOrientation ¶
func SexualOrientation() string
func SimplePassword ¶
func SimplePassword() string
SimplePassword is a wrapper around Password, it generates password with the length from 6 to 12 symbols, with upper characters and numeric symbols allowed
func StreetAddress ¶
func StreetAddress() string
StreetAddress generates random street name along with building number
func UseExternalData ¶
func UseExternalData(flag bool)
UseExternalData sets the flag that allows using of external files as data providers (fake uses embedded ones by default)
func UserName ¶
func UserName() string
UserName generates user name in one of the following forms first name + last name, letter + last names or concatenation of from 1 to 3 lowercased words
func WeekDayShort ¶
func WeekDayShort() string
WeekDayShort generates abbreviated name of the week day
Types ¶
This section is empty.