Documentation ¶
Index ¶
- Constants
- Variables
- func AddProvider(tag string, provider TaggedFunction) error
- func FakeData(a interface{}) error
- func RandomInt(parameters ...int) (p []int, err error)
- func RandomUnixTime() int64
- func SetAddress(net Addresser)
- func SetDataFaker(d DataFaker)
- func SetDateTimer(d DateTimer)
- func SetDowser(d Dowser)
- func SetNetwork(net Networker)
- func SetPayment(p Render)
- func SetPhoner(p Phoner)
- func SetPrice(p Money)
- type Address
- type Addresser
- type DataFaker
- type DateTime
- func (d DateTime) Century(v reflect.Value) (interface{}, error)
- func (d DateTime) Date(v reflect.Value) (interface{}, error)
- func (d DateTime) DayOfMonth(v reflect.Value) (interface{}, error)
- func (d DateTime) DayOfWeek(v reflect.Value) (interface{}, error)
- func (d DateTime) MonthName(v reflect.Value) (interface{}, error)
- func (d DateTime) Time(v reflect.Value) (interface{}, error)
- func (d DateTime) TimePeriod(v reflect.Value) (interface{}, error)
- func (d DateTime) TimeZone(v reflect.Value) (interface{}, error)
- func (d DateTime) Timestamp(v reflect.Value) (interface{}, error)
- func (d DateTime) UnixTime(v reflect.Value) (interface{}, error)
- func (d DateTime) Year(v reflect.Value) (interface{}, error)
- type DateTimer
- type Dowser
- type Identifier
- type Internet
- func (internet Internet) DomainName(v reflect.Value) (interface{}, error)
- func (internet Internet) Email(v reflect.Value) (interface{}, error)
- func (internet Internet) IPv4(v reflect.Value) (interface{}, error)
- func (internet Internet) IPv6(v reflect.Value) (interface{}, error)
- func (internet Internet) MacAddress(v reflect.Value) (interface{}, error)
- func (internet Internet) Password(v reflect.Value) (interface{}, error)
- func (internet Internet) URL(v reflect.Value) (interface{}, error)
- func (internet Internet) UserName(v reflect.Value) (interface{}, error)
- type Lorem
- type Money
- type Networker
- type Payment
- type Person
- func (p Person) FirstName(v reflect.Value) (interface{}, error)
- func (p Person) FirstNameFemale(v reflect.Value) (interface{}, error)
- func (p Person) FirstNameMale(v reflect.Value) (interface{}, error)
- func (p Person) LastName(v reflect.Value) (interface{}, error)
- func (p Person) Name(v reflect.Value) (interface{}, error)
- func (p Person) TitleFeMale(v reflect.Value) (interface{}, error)
- func (p Person) TitleMale(v reflect.Value) (interface{}, error)
- type Phone
- type Phoner
- type Price
- type Render
- type TaggedFunction
- type UUID
Constants ¶
const ( BaseDate = "2006-01-02" Time = "15:04:05" Month = "January" Year = "2006" Day = "Monday" DayOfMonth = "_2" TimePeriod = "PM" )
These example values must use the reference time "Mon Jan 2 15:04:05 MST 2006" as described at https://gobyexample.com/time-formatting-parsing
const ( ID = "uuid_digit" HyphenatedID = "uuid_hyphenated" Email = "email" MacAddress = "mac_address" DomainName = "domain_name" UserName = "username" URL = "url" IPV4 = "ipv4" IPV6 = "ipv6" PASSWORD = "password" LATITUDE = "lat" LONGITUDE = "long" CreditCardNumber = "cc_number" CreditCardType = "cc_type" PhoneNumber = "phone_number" TollFreeNumber = "tool_free_number" E164PhoneNumber = "e_164_phone_number" TitleMale = "title_male" TitleFemale = "title_female" FirstName = "first_name" FirstNameMale = "first_name_male" FirstNameFemale = "first_name_female" LastName = "last_name" NAME = "name" UnixTime = "unix_time" DATE = "date" TIME = "time" MonthName = "month_name" YEAR = "year" DayOfWeek = "day_of_week" DayOfMonthTag = "day_of_month" TIMESTAMP = "timestamp" CENTURY = "century" TIMEZONE = "timezone" TimePeriodTag = "time_period" WORD = "word" SENTENCE = "sentence" PARAGRAPH = "paragraph" Currency = "currency" Amount = "amount" AmountWithCurrency = "amount_with_currency" SKIP = "-" )
Supported tags
Variables ¶
var ( ErrUnsupportedKindPtr = "Unsupported kind: %s Change Without using * (pointer) in Field of %s" ErrUnsupportedKind = "Unsupported kind: %s" ErrValueNotPtr = "Not a pointer value" ErrTagNotSupported = "Tag unsupported" ErrTagAlreadyExists = "Tag exists" ErrMoreArguments = "Passed more arguments than is possible : (%d)" ErrNotSupportedPointer = "Use sample:=new(%s)\n faker.FakeData(sample) instead" )
Generic Error Messages for tags
ErrUnsupportedKindPtr: Error when get fake from ptr ErrUnsupportedKind: Error on passing unsupported kind ErrValueNotPtr: Error when value is not pointer ErrTagNotSupported: Error when tag is not supported ErrTagAlreadyExists: Error when tag exists and call AddProvider ErrMoreArguments: Error on passing more arguments ErrNotSupportedPointer: Error when passing unsupported pointer
Functions ¶
func AddProvider ¶ added in v1.5.0
func AddProvider(tag string, provider TaggedFunction) error
AddProvider extend faker with tag to generate fake data with specified custom algoritm
func FakeData ¶
func FakeData(a interface{}) error
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.
func RandomInt ¶ added in v1.3.0
RandomInt Get three parameters , only first mandatory and the rest are optional
If only set one parameter : This means the minimum number of digits and the total number If only set two parameters : First this is min digit and second max digit and the total number the difference between them If only three parameters: the third argument set Max count Digit
func RandomUnixTime ¶ added in v1.3.0
func RandomUnixTime() int64
RandomUnixTime is a helper function returning random Unix time
func SetDataFaker ¶ added in v1.3.0
func SetDataFaker(d DataFaker)
SetDataFaker sets Custom data in lorem
func SetDateTimer ¶ added in v1.3.0
func SetDateTimer(d DateTimer)
SetDateTimer sets custom date time
Types ¶
type Address ¶ added in v1.3.0
type Address struct{}
Address struct
type Addresser ¶ added in v1.3.0
type Addresser interface { Latitude(v reflect.Value) (interface{}, error) Longitude(v reflect.Value) (interface{}, error) }
Addresser is logical layer for Address
func GetAddress ¶ added in v1.3.0
func GetAddress() Addresser
GetAddress returns a new Addresser interface of Address
type DataFaker ¶ added in v1.3.0
type DataFaker interface { Word(v reflect.Value) (interface{}, error) Sentence(v reflect.Value) (interface{}, error) Paragraph(v reflect.Value) (interface{}, error) }
DataFaker generates randomized Words, Sentences and Paragraphs
type DateTime ¶ added in v1.3.0
type DateTime struct { }
DateTime struct
func (DateTime) DayOfMonth ¶ added in v1.3.0
DayOfMonth formats DateTime using example DayOfMonth const
func (DateTime) TimePeriod ¶ added in v1.3.0
TimePeriod formats DateTime using example TimePeriod const
func (DateTime) Timestamp ¶ added in v1.3.0
Timestamp formats DateTime using example Timestamp const
type DateTimer ¶ added in v1.3.0
type DateTimer interface { UnixTime(v reflect.Value) (interface{}, error) Date(v reflect.Value) (interface{}, error) Time(v reflect.Value) (interface{}, error) MonthName(v reflect.Value) (interface{}, error) Year(v reflect.Value) (interface{}, error) DayOfWeek(v reflect.Value) (interface{}, error) DayOfMonth(v reflect.Value) (interface{}, error) Timestamp(v reflect.Value) (interface{}, error) Century(v reflect.Value) (interface{}, error) TimeZone(v reflect.Value) (interface{}, error) TimePeriod(v reflect.Value) (interface{}, error) }
A DateTimer contains random Time generators, returning time string in certain particular format
func GetDateTimer ¶ added in v1.3.0
func GetDateTimer() DateTimer
GetDateTimer returns a new DateTimer interface of DateTime
type Dowser ¶ added in v1.3.0
type Dowser interface { TitleMale(v reflect.Value) (interface{}, error) TitleFeMale(v reflect.Value) (interface{}, error) FirstName(v reflect.Value) (interface{}, error) FirstNameMale(v reflect.Value) (interface{}, error) FirstNameFemale(v reflect.Value) (interface{}, error) LastName(v reflect.Value) (interface{}, error) Name(v reflect.Value) (interface{}, error) }
Dowser provides interfaces to generate random logical Names with their initials
type Identifier ¶
type Identifier interface { Digit(v reflect.Value) (interface{}, error) Hyphenated(v reflect.Value) (interface{}, error) }
Identifier ...
type Internet ¶ added in v1.3.0
type Internet struct{}
Internet struct
func (Internet) DomainName ¶ added in v1.3.0
DomainName generates random domain name
func (Internet) MacAddress ¶ added in v1.3.0
MacAddress generates random MacAddress
type Lorem ¶ added in v1.3.0
type Lorem struct { }
Lorem struct
func (Lorem) Paragraph ¶ added in v1.5.0
Paragraph returns a series of sentences as a paragraph using the wordList const
type Money ¶ added in v1.5.0
type Money interface { Currency(v reflect.Value) (interface{}, error) Amount(v reflect.Value) (interface{}, error) AmountWithCurrency(v reflect.Value) (interface{}, error) }
Money provides an interface to generate a custom price with or without a random currency code
type Networker ¶ added in v1.3.0
type Networker interface { Email(v reflect.Value) (interface{}, error) MacAddress(v reflect.Value) (interface{}, error) DomainName(v reflect.Value) (interface{}, error) URL(v reflect.Value) (interface{}, error) UserName(v reflect.Value) (interface{}, error) IPv4(v reflect.Value) (interface{}, error) IPv6(v reflect.Value) (interface{}, error) Password(v reflect.Value) (interface{}, error) }
Networker is logical layer for Internet
func GetNetworker ¶ added in v1.3.0
func GetNetworker() Networker
GetNetworker returns a new Networker interface of Internet
type Payment ¶ added in v1.3.0
type Payment struct{}
Payment struct
func (Payment) CreditCardNumber ¶ added in v1.3.0
CreditCardNumber generated credit card number according to the card number rules
type Person ¶ added in v1.3.0
type Person struct { }
Person struct
func (Person) FirstNameFemale ¶ added in v1.3.0
FirstNameFemale retuns first names for females
func (Person) FirstNameMale ¶ added in v1.3.0
FirstNameMale retuns first names for males
func (Person) TitleFeMale ¶ added in v1.3.0
TitleFeMale generates random titles for females
type Phone ¶ added in v1.3.0
type Phone struct { }
Phone struct
func (Phone) E164PhoneNumber ¶ added in v1.3.0
E164PhoneNumber generates phone numbers of type: "+27113456789"
func (Phone) PhoneNumber ¶ added in v1.3.0
PhoneNumber generates phone numbers of type: "201-886-0269"
type Phoner ¶ added in v1.3.0
type Phoner interface { PhoneNumber(v reflect.Value) (interface{}, error) TollFreePhoneNumber(v reflect.Value) (interface{}, error) E164PhoneNumber(v reflect.Value) (interface{}, error) }
Phoner serves overall tele-phonic contact generator
type Price ¶ added in v1.5.0
type Price struct { }
Price struct
func (Price) Amount ¶ added in v1.5.0
Amount returns a random floating price amount with a random precision of [1,2] up to (10**8 - 1)
func (Price) AmountWithCurrency ¶ added in v1.5.0
AmountWithCurrency combines both price and currency together
type Render ¶ added in v1.3.0
type Render interface { CreditCardType(v reflect.Value) (interface{}, error) CreditCardNumber(v reflect.Value) (interface{}, error) }
Render contains Whole Random Credit Card Generators with their types
func GetPayment ¶ added in v1.3.0
func GetPayment() Render
GetPayment returns a new Render interface of Payment struct
type TaggedFunction ¶
TaggedFunction ...