Documentation ¶
Overview ¶
package pseudo is the fake data generator, heavily inspired by forgery and ffaker Ruby gems.
CoreStore: This package has been refactored to avoid package global variables and global settings which are an anti-pattern. In a multi store/language environment a package global language limits everything. Also the global PRNG got eliminate and reduces a mutex bottle neck. This package can also handle max_len values for generated data and supports embedded structs which implements sql.Scanner interface.
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).
Index ¶
- Constants
- func Asset(name string) ([]byte, error)
- func AssetDir(name string) ([]string, error)
- func AssetInfo(name string) (os.FileInfo, error)
- func AssetNames() []string
- func MustAsset(name string) []byte
- func RestoreAsset(dir, name string) error
- func RestoreAssets(dir, name string) error
- func WithTagFakeFunc(tag string, provider FakeFunc) optionFn
- func WithTagFakeFuncAlias(aliasTag ...string) optionFn
- type FakeFunc
- type Faker
- type Options
- type Service
- func (s *Service) Address() string
- func (s *Service) Brand() string
- func (s *Service) Character() string
- func (s *Service) Characters() string
- func (s *Service) CharactersN(n int) string
- func (s *Service) City() string
- func (s *Service) Clock() string
- func (s *Service) Color() string
- func (s *Service) Company() string
- func (s *Service) CompanyLegal() string
- func (s *Service) Continent() string
- func (s *Service) Country() string
- func (s *Service) CountryISO2() string
- func (s *Service) CreditCardNum(vendor string) string
- func (s *Service) CreditCardType() string
- func (s *Service) Currency() string
- func (s *Service) CurrencyCode() string
- func (s *Service) Date() string
- func (s *Service) Day() int
- func (s *Service) Digits() string
- func (s *Service) DigitsN(n int) string
- func (s *Service) Dob18() time.Time
- func (s *Service) DomainName() string
- func (s *Service) DomainZone() string
- func (s *Service) EmailAddress() string
- func (s *Service) EmailBody() string
- func (s *Service) EmailSubject(maxLen int) string
- func (s *Service) FakeData(ptr interface{}) error
- func (s *Service) FemaleFirstName() string
- func (s *Service) FemaleFullName() string
- func (s *Service) FemaleFullNameWithPrefix() string
- func (s *Service) FemaleFullNameWithSuffix() string
- func (s *Service) FemaleLastName() string
- func (s *Service) FemalePatronymic() string
- func (s *Service) FirstName() string
- func (s *Service) Float64() float64
- func (s *Service) FullName() string
- func (s *Service) FullNameWithPrefix() string
- func (s *Service) FullNameWithSuffix() string
- func (s *Service) Gender() string
- func (s *Service) GenderAbbrev() string
- func (s *Service) GetLangs() []string
- func (s *Service) HexColor() string
- func (s *Service) HexColorShort() string
- func (s *Service) ID() uint64
- func (s *Service) IPv4() string
- func (s *Service) IPv6() string
- func (s *Service) Industry() string
- func (s *Service) Intn(n int) int
- func (s *Service) JobTitle() string
- func (s *Service) Language() string
- func (s *Service) LastName() string
- func (s *Service) Latitude() float64
- func (s *Service) LatitudeDegrees() int
- func (s *Service) LatitudeDirection() string
- func (s *Service) LatitudeMinutes() int
- func (s *Service) LatitudeSeconds() int
- func (s *Service) Longitude() float64
- func (s *Service) LongitudeDegrees() int
- func (s *Service) LongitudeDirection() string
- func (s *Service) LongitudeMinutes() int
- func (s *Service) LongitudeSeconds() int
- func (s *Service) MacAddress() string
- func (s *Service) MaleFirstName() string
- func (s *Service) MaleFullName() string
- func (s *Service) MaleFullNameWithPrefix() string
- func (s *Service) MaleFullNameWithSuffix() string
- func (s *Service) MaleLastName() string
- func (s *Service) MalePatronymic() string
- func (s *Service) Model() string
- func (s *Service) Month() string
- func (s *Service) MonthNum() int
- func (s *Service) MonthShort() string
- func (s *Service) Paragraph(maxLen int) string
- func (s *Service) Paragraphs(maxLen int) string
- func (s *Service) ParagraphsN(n int, maxLen int) string
- func (s *Service) Password(atLeast, atMost int, allowUpper, allowNumeric, allowSpecial bool) string
- func (s *Service) Patronymic() string
- func (s *Service) Phone() string
- func (s *Service) Prefix() string
- func (s *Service) Price() float64
- func (s *Service) PriceWithCurrency() string
- func (s *Service) Product() string
- func (s *Service) ProductName() string
- func (s *Service) RandomUnixTime() int64
- func (s *Service) Sentence(maxLen int) string
- func (s *Service) Sentences(maxLen int) string
- func (s *Service) SentencesN(count int, maxLen int) string
- func (s *Service) SetLang(newLang string) error
- func (s *Service) SimplePassword() string
- func (s *Service) State() string
- func (s *Service) StateAbbrev() string
- func (s *Service) Street() string
- func (s *Service) StreetAddress() string
- func (s *Service) Suffix() string
- func (s *Service) Time() time.Time
- func (s *Service) TimeStamp() string
- func (s *Service) TimeZone() string
- func (s *Service) Title() string
- func (s *Service) TopLevelDomain() string
- func (s *Service) ULID() ulid.ULID
- func (s *Service) URL() string
- func (s *Service) UUID() []byte
- func (s *Service) UUIDString() string
- func (s *Service) UserName() string
- func (s *Service) WeekDay() string
- func (s *Service) WeekDayShort() string
- func (s *Service) WeekdayNum() int
- func (s *Service) Word(maxLen int) string
- func (s *Service) Words(maxLen int) string
- func (s *Service) WordsN(n int, maxLen int) string
- func (s *Service) Year(from, to int) int
- func (s *Service) Zip() string
Constants ¶
const ( // Skip indicates a struct tag, that the field should be skipped. Skip = "-" DefaultMaxRecursionLevel = 10 )
Supported tags
Variables ¶
This section is empty.
Functions ¶
func Asset ¶
Asset loads and returns the asset for the given name. It returns an error if the asset could not be found or could not be loaded.
func AssetDir ¶
AssetDir returns the file names below a certain directory embedded in the file by go-bindata. For example if you run go-bindata on data/... and data contains the following hierarchy:
data/ foo.txt img/ a.png b.png
then AssetDir("data") would return []string{"foo.txt", "img"} AssetDir("data/img") would return []string{"a.png", "b.png"} AssetDir("foo.txt") and AssetDir("notexist") would return an error AssetDir("") will return []string{"data"}.
func AssetInfo ¶
AssetInfo loads and returns the asset info for the given name. It returns an error if the asset could not be found or could not be loaded.
func AssetNames ¶
func AssetNames() []string
AssetNames returns the names of the assets. nolint: deadcode
func MustAsset ¶
MustAsset is like Asset but panics when Asset would return an error. It simplifies safe initialization of global variables. nolint: deadcode
func RestoreAsset ¶
RestoreAsset restores an asset under the given directory
func RestoreAssets ¶
RestoreAssets restores an asset under the given directory recursively
func WithTagFakeFunc ¶
WithTagFakeFunc extends faker with a new tag (or field name) to generate fake data with a specified custom algorithm. It will overwrite a previous set function.
func WithTagFakeFuncAlias ¶
func WithTagFakeFuncAlias(aliasTag ...string) optionFn
WithTagFakeFuncAlias sets a new alias. E.g. when WithTagFakeFunc("http",...) adds a function to generate HTTP links, then calling WithTagFakeFuncAlias("https","http","ftps","ftp") would say that https is an alias of the http function and ftps is an alias of ftp.
Types ¶
type FakeFunc ¶
type FakeFunc func(maxLen int) interface{}
FakeFunc generates new specific fake values. The returned interface{} type can only contain primitive types and time.Time.
type Faker ¶
Faker allows a type to implement a custom fake data generation. The argument fieldName contains the name of the current field for which random/fake data should be generated. The return argument hasFakeDataApplied can be set to true, if fake data gets generated for the current field. Setting hasFakeDataApplied to false, the fake data should be generated by this package.
type Options ¶
type Options struct { Lang string UseExternalData bool EnFallback bool TimeLocation *time.Location // defaults to UTC // RespectValidField if enabled allows to observe the `Valid bool` field of // a struct. Like sql.NullString, sqlNullInt64 or all null.* types. If Valid // is false, the other fields will be reset to their repective default // values. Reason: All fields of a struct are getting applied with fake // data, if Valid is false and the field gets written to the e.g. DB and // later compared. RespectValidField bool // DisabledFieldNameUse if enabled avoids the usage of the field name // instead of the struct tag to find out which kind of random function is // needed. DisabledFieldNameUse bool // MaxLenStringLimit defines the upper bound of the maximal length for a // string. If not set, defaults to 512. MaxLenStringLimit uint64 // MaxFloatDecimals limits the float generation to this amount of decimals. // Useful for MySQL/MariaDB float column type. MaxFloatDecimals int // MaxRecursionLevel default see DefaultMaxRecursionLevel MaxRecursionLevel int }
Options applied for the Service type.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service provides a service to generate fake data.
func MustNewService ¶
MustNewService creates a new Service but panics on error.
func NewService ¶
NewService creates a new fake service.
func (*Service) Characters ¶
Characters generates from 1 to 5 characters in the given language
func (*Service) CharactersN ¶
CharactersN generates n random characters in the given language
func (*Service) CompanyLegal ¶
Company generates company name
func (*Service) CountryISO2 ¶
CountryISO2 generates a random country iso2 code
func (*Service) CreditCardNum ¶
CreditCardNum generated credit card number according to the card number rules
func (*Service) CreditCardType ¶
CreditCardType returns one of the following credit values: VISA, MasterCard, American Express and Discover
func (*Service) CurrencyCode ¶
CurrencyCode generates currency code.
func (*Service) Dob18 ¶
Dob18 returns a date of birth in the format 2006-01-02 00:00:00 with a minimum age of 18 years.
func (*Service) DomainName ¶
DomainName generates random domain name
func (*Service) DomainZone ¶
DomainZone generates random domain zone
func (*Service) EmailAddress ¶
EmailAddress generates email address
func (*Service) EmailSubject ¶
EmailSubject generates random email subject
func (*Service) FakeData ¶
FakeData is the main function. Will generate a fake data based on your struct. You can use this for automation testing, or anything that need automated data. You don't need to Create your own data for your testing. Unsupported types are getting ignored.
func (*Service) FemaleFirstName ¶
FemaleFirstName generates female first name
func (*Service) FemaleFullName ¶
FemaleFullName generates female full name it can occasionally include prefix or suffix
func (*Service) FemaleFullNameWithPrefix ¶
FemaleFullNameWithPrefix generates prefixed female full name if prefixes for the given language are available
func (*Service) FemaleFullNameWithSuffix ¶
FemaleFullNameWithSuffix generates suffixed female full name if suffixes for the given language are available
func (*Service) FemaleLastName ¶
FemaleLastName generates female last name
func (*Service) FemalePatronymic ¶
FemalePatronymic generates female patronymic
func (*Service) FullName ¶
FullName generates full name it can occasionally include prefix or suffix
func (*Service) FullNameWithPrefix ¶
FullNameWithPrefix generates prefixed full name if prefixes for the given language are available
func (*Service) FullNameWithSuffix ¶
FullNameWithSuffix generates suffixed full name if suffixes for the given language are available
func (*Service) GenderAbbrev ¶
GenderAbbrev returns first downcased letter of the random gender
func (*Service) HexColorShort ¶
HexColorShort generates short hex color name
func (*Service) LatitudeDegrees ¶
LatitudeDegrees generates latitude degrees (from -90 to 90)
func (*Service) LatitudeDirection ¶
LatitudeDirection generates latitude direction (N(orth) o S(outh))
func (*Service) LatitudeMinutes ¶
LatitudeMinutes generates latitude minutes (from 0 to 60)
func (*Service) LatitudeSeconds ¶
LatitudeSeconds generates latitude seconds (from 0 to 60)
func (*Service) LongitudeDegrees ¶
LongitudeDegrees generates longitude degrees (from -180 to 180)
func (*Service) LongitudeDirection ¶
LongitudeDirection generates (W(est) or E(ast))
func (*Service) LongitudeMinutes ¶
LongitudeMinutes generates (from 0 to 60)
func (*Service) LongitudeSeconds ¶
LongitudeSeconds generates (from 0 to 60)
func (*Service) MacAddress ¶
MacAddress generates random MacAddress
func (*Service) MaleFirstName ¶
MaleFirstName generates male first name
func (*Service) MaleFullName ¶
MaleFullName generates male full name it can occasionally include prefix or suffix
func (*Service) MaleFullNameWithPrefix ¶
MaleFullNameWithPrefix generates prefixed male full name if prefixes for the given language are available
func (*Service) MaleFullNameWithSuffix ¶
MaleFullNameWithSuffix generates suffixed male full name if suffixes for the given language are available
func (*Service) MaleLastName ¶
MaleLastName generates male last name
func (*Service) MalePatronymic ¶
MalePatronymic generates male patronymic
func (*Service) Model ¶
Model generates model name that consists of letters and digits, optionally with a hyphen between them
func (*Service) MonthShort ¶
MonthShort generates abbreviated month name
func (*Service) Paragraphs ¶
Paragraphs generates from 1 to 5 paragraphs
func (*Service) ParagraphsN ¶
ParagraphsN generates n paragraphs
func (*Service) Password ¶
Password generates password with the length from atLeast to atMOst charachers, allow* parameters specify whether corresponding symbols can be used
func (*Service) Phone ¶
Phone generates random phone number using one of the formats format specified in phone_format file
func (*Service) Prefix ¶
Prefix returns a random prefix for either a female or male, sometimes an empty prefix.
func (*Service) Price ¶
Amount returns a random floating price amount with a random precision of [1,2] up to (10**8 - 1)
func (*Service) PriceWithCurrency ¶
PriceWithCurrency combines both price and currency together
func (*Service) ProductName ¶
ProductName generates product name
func (*Service) RandomUnixTime ¶
RandomUnixTime returns a random unix time stamp between now and the last 6 years.
func (*Service) Sentence ¶
Sentence generates random sentence. If maxLen > 0, it will be considered as the total length of one sentence. The sentence gets cut after maxLen bytes.
func (*Service) SentencesN ¶
SentencesN generates n random sentences
func (*Service) SetLang ¶
SetLang sets the language in which the data should be generated returns error if passed language is not available
func (*Service) SimplePassword ¶
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 (*Service) StateAbbrev ¶
StateAbbrev generates random state abbreviation
func (*Service) StreetAddress ¶
StreetAddress generates random street name along with building number
func (*Service) Suffix ¶
Prefix returns a random prefix for either a female or male, sometimes an empty prefix.
func (*Service) TopLevelDomain ¶
TopLevelDomain generates random top level domain
func (*Service) ULID ¶
ULID returns an ULID which is a 16 byte Universally Unique Lexicographically Sortable Identifier.
func (*Service) UUIDString ¶
UUID returns a UUID v4 as string.
func (*Service) UserName ¶
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 (*Service) WeekDayShort ¶
WeekDayShort generates abbreviated name of the week day
func (*Service) WeekdayNum ¶
WeekdayNum generates number of the day of the week