Documentation ¶
Overview ¶
Package fake is the fake data generatror for go (Golang), heavily inspired by forgery and ffaker Ruby gems
Most data and methods are ported from forgery/ffaker Ruby gems.
Currently english and russian languages are available.
For the list of available methods please look at https://godoc.org/github.com/icrowley/fake.
Fake embeds samples data files unless you call UseExternalData(true) in order to be able to work without external files dependencies when compiled, so, if you add new data files or make changes to existing ones don't forget to regenerate data.go file using github.com/mjibson/esc tool and esc -o data.go -pkg fake data command (or you can just use go generate command if you are using Go 1.4 or later).
Examples:
name := fake.FirstName() fullname = := fake.FullName() product := fake.Product()
Changing language:
err := fake.SetLang("ru") if err != nil { panic(err) } password := fake.SimplePassword()
Using english fallback:
err := fake.SetLang("ru") if err != nil { panic(err) } fake.EnFallback(true) password := fake.Paragraph()
Using external data:
fake.UseExternalData(true) password := fake.Paragraph()
Index ¶
- Variables
- func Brand() string
- func Character() string
- func Characters() string
- func CharactersN(n int) string
- 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 EmailAddress() string
- func EmailBody() string
- func EmailSubject() string
- func EnFallback(flag bool)
- 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 Latitude() float32
- func LatitudeDegrees() int
- func LatitudeDirection() string
- func LatitudeMinutes() int
- func LatitudeSeconds() int
- 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 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 Seed(seed int64)
- func Sentence() string
- func Sentences() string
- func SentencesN(n int) string
- func SetLang(newLang string) error
- func SimplePassword() string
- func State() string
- func StateAbbrev() string
- func Street() string
- func StreetAddress() string
- func Title() string
- func TopLevelDomain() string
- func UseExternalData(flag bool)
- func UserAgent() string
- func UserName() string
- func WeekDay() string
- func WeekDayShort() string
- func WeekdayNum() int
- func Word() string
- func Words() string
- func WordsN(n int) string
- func Year(from, to int) int
- func Zip() string
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNoLanguageFn is the error that indicates that given language is not available ErrNoLanguageFn = func(lang string) error { return fmt.Errorf("The language passed (%s) is not available", lang) } // ErrNoSamplesFn is the error that indicates that there are no samples for the given language ErrNoSamplesFn = func(lang string) error { return fmt.Errorf("No samples found for language: %s", lang) } )
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 CreditCardNum ¶
CreditCardNum generated credit card number according to the card number rules
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 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 -90 to 90)
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 returns error if passed language is not available
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.