Documentation ¶
Overview ¶
Package faker contains a random data generator (faker) with over 130 functions and has 2 modes: fast or (concurrent) safe. Can be used to mock data, test or stress test your systems or databases. You can generate almost anything, from names, addresses to prices and vehicle transmission types.
If you are looking for a HTTP service with the same functionality, not a package see Pseudoservice, it is a wrapper on FastFaker https://github.com/bgadrian/pseudoservice
Usage:
import "github.com/bgadrian/fastfaker/faker"
Method 1, use the Global instance (simple and concurrent safe):
fmt.Println("Name:", Global.Name()) //Name: Markus Moen
Method 2, instantiate a concurrent safe version:
faker := NewSafeFaker() fmt.Println("Email:", faker.Email()) //kimsteuber@jones.com
Method 3, create a fast faker that is Not safe to use from multiple goroutines:
faker := NewFastFaker() fmt.Println(Global.Template("{name} drinks {beername}.")) //Adrian drinks Duvel.
Fakers take their data from the github.com/bgadrian/fastfaker/data package. The pseudo-random algorithm is provided by the github.com/bgadrian/fastfaker/randomizer package, that is a wrapper of the rand package from the standard library.
For a more advanced overview of the Template feature see https://github.com/bgadrian/fastfaker/blob/master/TEMPLATES.md
Example ¶
Global.Seed(11) fmt.Println("Name:", Global.Name()) fmt.Println("Email:", Global.Email()) fmt.Println("Phone:", Global.Phone()) fmt.Println("Address:", Global.Address().Address) fmt.Println("BS:", Global.BS()) fmt.Println("Beer Name:", Global.BeerName()) fmt.Println("Color:", Global.Color()) fmt.Println("Company:", Global.Company()) fmt.Println("Credit Card:", Global.CreditCardNumber()) fmt.Println("Hacker Phrase:", Global.HackerPhrase()) fmt.Println("Job Title:", Global.JobTitle()) fmt.Println("Password:", Global.Password(true, true, true, true, true, 32)) currency := Global.Currency() fmt.Printf("Currency: %s - %s", currency.Short, currency.Long)
Output: Name: Markus Moen Email: alaynawuckert@kozey.biz Phone: 7625013191 Address: 8995 Wellport, North Denesik, Indiana 30042 BS: networks Beer Name: Arrogant Bastard Ale Color: Black Company: Pagac, Ratke and Stracke Credit Card: 6502027613217148 Hacker Phrase: Use the open-source JSON system, then you can bypass the optical microchip! Job Title: Strategist Password: SvH*aQzqA *snbo2?z-O=zJn1L# iu u Currency: ZAR - South Africa Rand
Index ¶
- Constants
- Variables
- type AddressInfo
- type ContactInfo
- type CreditCardInfo
- type CurrencyInfo
- type Faker
- func (f *Faker) Address() *AddressInfo
- func (f *Faker) AvatarURL() string
- func (f *Faker) BS() string
- func (f *Faker) BeerAlcohol() string
- func (f *Faker) BeerBlg() string
- func (f *Faker) BeerHop() string
- func (f *Faker) BeerIbu() string
- func (f *Faker) BeerMalt() string
- func (f *Faker) BeerName() string
- func (f *Faker) BeerStyle() string
- func (f *Faker) BeerYeast() string
- func (f *Faker) Binary() string
- func (f *Faker) Bool() bool
- func (f *Faker) BoolText() string
- func (f *Faker) Browser() string
- func (f *Faker) BuzzWord() string
- func (f *Faker) CarMaker() string
- func (f *Faker) CarModel() string
- func (f *Faker) ChromeUserAgent() string
- func (f *Faker) City() (city string)
- func (f *Faker) Color() string
- func (f *Faker) Company() (company string)
- func (f *Faker) CompanySuffix() string
- func (f *Faker) Contact() *ContactInfo
- func (f *Faker) Country() string
- func (f *Faker) CountryAbr() string
- func (f *Faker) CreditCard() *CreditCardInfo
- func (f *Faker) CreditCardCvv() string
- func (f *Faker) CreditCardExp() string
- func (f *Faker) CreditCardNumber() int
- func (f *Faker) CreditCardNumberLuhn() int
- func (f *Faker) CreditCardType() string
- func (f *Faker) Currency() *CurrencyInfo
- func (f *Faker) CurrencyLong() string
- func (f *Faker) CurrencyShort() string
- func (f *Faker) Date() time.Time
- func (f *Faker) DateCurrentYear() time.Time
- func (f *Faker) DateCurrentYearStr() string
- func (f *Faker) DateRange(start, end time.Time) time.Time
- func (f *Faker) DateStr() string
- func (f *Faker) Day() int
- func (f *Faker) Digit() string
- func (f *Faker) DomainName() string
- func (f *Faker) DomainSuffix() string
- func (f *Faker) Email() string
- func (f *Faker) Extension() string
- func (f *Faker) FirefoxUserAgent() string
- func (f *Faker) FirstName() string
- func (f *Faker) FuelType() string
- func (f *Faker) Gender() string
- func (f *Faker) HTTPMethod() string
- func (f *Faker) HackerAbbreviation() string
- func (f *Faker) HackerAdjective() string
- func (f *Faker) HackerIngverb() string
- func (f *Faker) HackerNoun() string
- func (f *Faker) HackerPhrase() string
- func (f *Faker) HackerVerb() string
- func (f *Faker) HexColor() string
- func (f *Faker) Hexify(str string) string
- func (f *Faker) HipsterParagraph(paragraphCount int, sentenceCount int, wordCount int, separator string) string
- func (f *Faker) HipsterParagraphAvg() string
- func (f *Faker) HipsterSentence(wordCount int) string
- func (f *Faker) HipsterSentenceAvg() string
- func (f *Faker) HipsterWord() string
- func (f *Faker) Hour() int
- func (f *Faker) IPv4Address() string
- func (f *Faker) IPv6Address() string
- func (f *Faker) ImageURL(width int, height int) string
- func (f *Faker) Job() *JobInfo
- func (f *Faker) JobDescriptor() string
- func (f *Faker) JobLevel() string
- func (f *Faker) JobTitle() string
- func (f *Faker) Language() string
- func (f *Faker) LanguageAbbreviation() string
- func (f *Faker) LastName() string
- func (f *Faker) Latitude() float64
- func (f *Faker) LatitudeInRange(min, max float64) (float64, error)
- func (f *Faker) Letter() string
- func (f *Faker) Lexify(str string) string
- func (f *Faker) LogLevel(logType string) string
- func (f *Faker) Longitude() float64
- func (f *Faker) LongitudeInRange(min, max float64) (float64, error)
- func (f *Faker) MD5() string
- func (f *Faker) MacAddress() string
- func (f *Faker) Map() map[string]interface{}
- func (f *Faker) MimeType() string
- func (f *Faker) Minute() int
- func (f *Faker) Month() string
- func (f *Faker) Name() string
- func (f *Faker) NamePrefix() string
- func (f *Faker) NameSuffix() string
- func (f *Faker) NanoSecond() int
- func (f *Faker) Numerify(str string) string
- func (f *Faker) OperaUserAgent() string
- func (f *Faker) Paragraph(paragraphCount int, sentenceCount int, wordCount int, separator string) string
- func (f *Faker) ParagraphAvg() string
- func (f *Faker) Password(lower bool, upper bool, numeric bool, special bool, space bool, num int) string
- func (f *Faker) PasswordFull() string
- func (f *Faker) Person() *PersonInfo
- func (f *Faker) Phone() string
- func (f *Faker) PhoneFormatted() string
- func (f *Faker) Price(min, max float64) float64
- func (f *Faker) ProgrammingLanguage() string
- func (f *Faker) Question() string
- func (f *Faker) Quote() string
- func (f *Faker) RGBColor() []int
- func (f *Faker) RandString(a []string) string
- func (f *Faker) SHA256() string
- func (f *Faker) SSN() string
- func (f *Faker) SafariUserAgent() string
- func (f *Faker) SafeColor() string
- func (f *Faker) Second() int
- func (f *Faker) Sentence(wordCount int) string
- func (f *Faker) SentenceAvg() string
- func (f *Faker) ShuffleStrings(a []string)
- func (f *Faker) SimpleStatusCode() int
- func (f *Faker) SliceStrings() []string
- func (f *Faker) State() string
- func (f *Faker) StateAbr() string
- func (f *Faker) StatusCode() int
- func (f *Faker) Street() (street string)
- func (f *Faker) StreetName() string
- func (f *Faker) StreetNumber() string
- func (f *Faker) StreetPrefix() string
- func (f *Faker) StreetSuffix() string
- func (f *Faker) Struct(v interface{})
- func (f *Faker) Template(pattern string) string
- func (f *Faker) TemplateCustom(template, delimStart, delimEnd string) (string, error)
- func (f *Faker) TimeZone() string
- func (f *Faker) TimeZoneAbv() string
- func (f *Faker) TimeZoneFull() string
- func (f *Faker) TimeZoneOffset() float32
- func (f *Faker) TransmissionGearType() string
- func (f *Faker) URL() string
- func (f *Faker) UUID() string
- func (f *Faker) UserAgent() string
- func (f *Faker) Username() string
- func (f *Faker) Vehicle() *VehicleInfo
- func (f *Faker) VehicleType() string
- func (f *Faker) WeekDay() string
- func (f *Faker) Word() string
- func (f *Faker) Year() int
- func (f *Faker) Zip() string
- type JobInfo
- type PersonInfo
- type VehicleInfo
Examples ¶
- Package
- Faker.Address
- Faker.AvatarURL
- Faker.BS
- Faker.BeerAlcohol
- Faker.BeerBlg
- Faker.BeerHop
- Faker.BeerIbu
- Faker.BeerMalt
- Faker.BeerName
- Faker.BeerStyle
- Faker.BeerYeast
- Faker.Binary
- Faker.Bool
- Faker.BoolText
- Faker.BuzzWord
- Faker.CarMaker
- Faker.CarModel
- Faker.ChromeUserAgent
- Faker.City
- Faker.Color
- Faker.Company
- Faker.CompanySuffix
- Faker.Contact
- Faker.Country
- Faker.CountryAbr
- Faker.CreditCard
- Faker.CreditCardCvv
- Faker.CreditCardExp
- Faker.CreditCardNumber
- Faker.CreditCardNumberLuhn
- Faker.CreditCardType
- Faker.Currency
- Faker.CurrencyLong
- Faker.CurrencyShort
- Faker.Date
- Faker.DateCurrentYear
- Faker.DateCurrentYearStr
- Faker.DateRange
- Faker.DateStr
- Faker.Day
- Faker.Digit
- Faker.DomainName
- Faker.DomainSuffix
- Faker.Email
- Faker.Extension
- Faker.FirefoxUserAgent
- Faker.FirstName
- Faker.FuelType
- Faker.Gender
- Faker.HTTPMethod
- Faker.HackerAbbreviation
- Faker.HackerAdjective
- Faker.HackerIngverb
- Faker.HackerNoun
- Faker.HackerPhrase
- Faker.HackerVerb
- Faker.HexColor
- Faker.Hexify
- Faker.HipsterParagraph
- Faker.HipsterParagraphAvg
- Faker.HipsterSentence
- Faker.HipsterSentenceAvg
- Faker.HipsterWord
- Faker.Hour
- Faker.IPv4Address
- Faker.IPv6Address
- Faker.ImageURL
- Faker.Job
- Faker.JobDescriptor
- Faker.JobLevel
- Faker.JobTitle
- Faker.LastName
- Faker.Latitude
- Faker.LatitudeInRange
- Faker.Letter
- Faker.Lexify
- Faker.LogLevel
- Faker.Longitude
- Faker.LongitudeInRange
- Faker.MD5
- Faker.MimeType
- Faker.Minute
- Faker.Month
- Faker.Name
- Faker.NamePrefix
- Faker.NameSuffix
- Faker.NanoSecond
- Faker.Numerify
- Faker.OperaUserAgent
- Faker.Paragraph
- Faker.ParagraphAvg
- Faker.Password
- Faker.PasswordFull
- Faker.Person
- Faker.Phone
- Faker.PhoneFormatted
- Faker.Price
- Faker.RGBColor
- Faker.SHA256
- Faker.SSN
- Faker.SafariUserAgent
- Faker.SafeColor
- Faker.Second
- Faker.Sentence
- Faker.SentenceAvg
- Faker.ShuffleStrings
- Faker.SimpleStatusCode
- Faker.State
- Faker.StateAbr
- Faker.StatusCode
- Faker.Street
- Faker.StreetName
- Faker.StreetNumber
- Faker.StreetPrefix
- Faker.StreetSuffix
- Faker.Struct
- Faker.Template
- Faker.Template (Html)
- Faker.Template (Json)
- Faker.Template (Yaml)
- Faker.TimeZone
- Faker.TimeZoneAbv
- Faker.TimeZoneFull
- Faker.TimeZoneOffset
- Faker.TransmissionGearType
- Faker.URL
- Faker.UUID
- Faker.UserAgent
- Faker.Username
- Faker.Vehicle
- Faker.VehicleType
- Faker.WeekDay
- Faker.Word
- Faker.Year
- Faker.Zip
- NewFastFaker
Constants ¶
const TemplateAllowedDelimiters = "{}%#~<>-:@`"
TemplateAllowedDelimiters the runes that are allowed as variable delimiters in Custom Templates. Must be ASCII (1 byte size) and not interfere with the regex expressions.
Variables ¶
var ErrRangeInvalid = errors.New("input range is invalid")
ErrRangeInvalid signals a bad input
Functions ¶
This section is empty.
Types ¶
type AddressInfo ¶
type AddressInfo struct { Address string Street string City string State string Zip string Country string Latitude float64 Longitude float64 }
AddressInfo is a struct full of address information
type ContactInfo ¶
ContactInfo struct full of contact info
type CreditCardInfo ¶
CreditCardInfo is a struct containing credit variables
type CurrencyInfo ¶
CurrencyInfo is a struct of currency information
type Faker ¶
type Faker struct {
*randomizer.RandWrapper
}
Faker is the main strut that encapsulate all the package functionality.
var Global *Faker
Global is a singleton, safe for concurrency instance of a Faker.
func NewFastFaker ¶
func NewFastFaker() *Faker
NewFastFaker generates a new Faker instance that CANNOT be used from multiple goroutines in the same time. Its state is non-deterministic (seeded with a random value) but you can use the .Seed() method. Use this faker when you want better performance in a multi-thread scenario.
Example ¶
//create only one instance per goroutine! faker := NewFastFaker() faker.Seed(42) fmt.Println("Name:", faker.Name()) fmt.Println("Email:", faker.Email())
Output: Name: Jeromy Schmeler Email: kimsteuber@jones.com
func NewSafeFaker ¶
func NewSafeFaker() *Faker
NewSafeFaker creates a new Faker instance that can be used in a concurrent/parallel env. Its state is non-deterministic (seeded with a random value) but you can use the .Seed() method. It uses a mutex, so the performance may be affected.
func (*Faker) Address ¶
func (f *Faker) Address() *AddressInfo
Address will generate a struct of address information
Example ¶
Global.Seed(11) address := Global.Address() fmt.Println(address.Address) fmt.Println(address.Street) fmt.Println(address.City) fmt.Println(address.State) fmt.Println(address.Zip) fmt.Println(address.Country) fmt.Println(address.Latitude) fmt.Println(address.Longitude) // 872 East Rapidsborough, Rutherfordstad, New Jersey 74853 // 872 East Rapidsborough // Rutherfordstad // New Jersey // 74853 // South Africa // 23.05875828427908 // 89.02259415693374
Output:
func (*Faker) AvatarURL ¶
AvatarURL will generate a random image URL of 80x80 px. Images Provided by pipsum.com
Example ¶
Global.Seed(42) fmt.Println(Global.AvatarURL())
Output: http://pipsum.com/80x80.jpg
func (*Faker) BS ¶
BS will generate a random company bs string
Example ¶
Global.Seed(11) fmt.Println(Global.BS())
Output: front-end
func (*Faker) BeerAlcohol ¶
BeerAlcohol will return a random beer alcohol level between 2.0 and 10.0
Example ¶
Global.Seed(11) fmt.Println(Global.BeerAlcohol())
Output: 2.7%
func (*Faker) BeerBlg ¶
BeerBlg will return a random beer blg between 5.0 and 20.0
Example ¶
Global.Seed(11) fmt.Println(Global.BeerBlg())
Output: 6.4°Blg
func (*Faker) BeerHop ¶
BeerHop will return a random beer hop
Example ¶
Global.Seed(11) fmt.Println(Global.BeerHop())
Output: Glacier
func (*Faker) BeerIbu ¶
BeerIbu will return a random beer ibu value between 10 and 100
Example ¶
Global.Seed(11) fmt.Println(Global.BeerIbu())
Output: 29 IBU
func (*Faker) BeerMalt ¶
BeerMalt will return a random beer malt
Example ¶
Global.Seed(11) fmt.Println(Global.BeerMalt())
Output: Munich
func (*Faker) BeerName ¶
BeerName will return a random beer name
Example ¶
Global.Seed(11) fmt.Println(Global.BeerName())
Output: Duvel
func (*Faker) BeerStyle ¶
BeerStyle will return a random beer style
Example ¶
Global.Seed(11) fmt.Println(Global.BeerStyle())
Output: European Amber Lager
func (*Faker) BeerYeast ¶
BeerYeast will return a random beer yeast
Example ¶
Global.Seed(11) fmt.Println(Global.BeerYeast())
Output: 1388 - Belgian Strong Ale
func (*Faker) Binary ¶
Binary will generate a random binary value "0" or "1" Can be used for configs or generating binary values.
Example ¶
Global.Seed(11) //will return a string value ("0" or "1") fmt.Println(Global.Binary()) fmt.Println(Global.Binary())
Output: 0 1
func (*Faker) Bool ¶
Bool will generate a random boolean value
Example ¶
Global.Seed(11) //it returns a Go boolean value fmt.Println(Global.Bool())
Output: false
func (*Faker) BoolText ¶
BoolText will generate a random boolean value as text, "true" or "false". Can be used for JSON/YAML templates boolean values
Example ¶
Global.Seed(11) //wil return a string value ("true" or "false") fmt.Println(Global.BoolText()) fmt.Println(Global.BoolText())
Output: false true
func (*Faker) BuzzWord ¶
BuzzWord will generate a random company buzz word string
Example ¶
Global.Seed(11) fmt.Println(Global.BuzzWord())
Output: disintermediate
func (*Faker) CarMaker ¶
CarMaker will generate a random car manufacturer
Example ¶
Global.Seed(11) fmt.Println(Global.CarMaker())
Output: Nissan
func (*Faker) CarModel ¶
CarModel will generate a random car model
Example ¶
Global.Seed(11) fmt.Println(Global.CarModel())
Output: Aveo
func (*Faker) ChromeUserAgent ¶
ChromeUserAgent will generate a random chrome browser user agent string
Example ¶
Global.Seed(11) fmt.Println(Global.ChromeUserAgent())
Output: Mozilla/5.0 (X11; Linux i686) AppleWebKit/5312 (KHTML, like Gecko) Chrome/39.0.836.0 Mobile Safari/5312
func (*Faker) City ¶
City will generate a random city string
Example ¶
Global.Seed(11) fmt.Println(Global.City())
Output: Marcelside
func (*Faker) Color ¶
Color will generate a random color string
Example ¶
Global.Seed(11) fmt.Println(Global.Color())
Output: MediumOrchid
func (*Faker) Company ¶
Company will generate a random company name string
Example ¶
Global.Seed(11) fmt.Println(Global.Company())
Output: Moen, Pagac and Wuckert
func (*Faker) CompanySuffix ¶
CompanySuffix will generate a random company suffix string
Example ¶
Global.Seed(11) fmt.Println(Global.CompanySuffix())
Output: Inc
func (*Faker) Contact ¶
func (f *Faker) Contact() *ContactInfo
Contact will generate a struct with information randomly populated contact information
Example ¶
Global.Seed(11) contact := Global.Contact() fmt.Println(contact.Phone) fmt.Println(contact.Email)
Output: 7787046119 marcelpagac@wuckert.biz
func (*Faker) Country ¶
Country will generate a random country string
Example ¶
Global.Seed(11) fmt.Println(Global.Country())
Output: Tajikistan
func (*Faker) CountryAbr ¶
CountryAbr will generate a random abbreviated country string
Example ¶
Global.Seed(11) fmt.Println(Global.CountryAbr())
Output: FI
func (*Faker) CreditCard ¶
func (f *Faker) CreditCard() *CreditCardInfo
CreditCard will generate a struct full of credit card information
Example ¶
Global.Seed(11) ccInfo := Global.CreditCard() fmt.Println(ccInfo.Type) fmt.Println(ccInfo.Number) fmt.Println(ccInfo.Exp) fmt.Println(ccInfo.Cvv)
Output: Visa 6536459948995369 03/26 353
func (*Faker) CreditCardCvv ¶
CreditCardCvv will generate a random CVV number - Its a string because you could have 017 as an exp date
Example ¶
Global.Seed(11) fmt.Println(Global.CreditCardCvv())
Output: 013
func (*Faker) CreditCardExp ¶
CreditCardExp will generate a random credit card expiration date string Exp date will always be a future date
Example ¶
Global.Seed(11) fmt.Println(Global.CreditCardExp())
Output: 01/21
func (*Faker) CreditCardNumber ¶
CreditCardNumber will generate a random credit card number int
Example ¶
Global.Seed(11) fmt.Println(Global.CreditCardNumber())
Output: 4136459948995369
func (*Faker) CreditCardNumberLuhn ¶
CreditCardNumberLuhn will generate a random credit card number int that passes luhn test
Example ¶
Global.Seed(11) fmt.Println(Global.CreditCardNumberLuhn())
Output: 2720996615546177
func (*Faker) CreditCardType ¶
CreditCardType will generate a random credit card type string
Example ¶
Global.Seed(11) fmt.Println(Global.CreditCardType())
Output: Visa
func (*Faker) Currency ¶
func (f *Faker) Currency() *CurrencyInfo
Currency will generate a struct with random currency information
Example ¶
Global.Seed(11) currency := Global.Currency() fmt.Printf("%s - %s", currency.Short, currency.Long)
Output: IQD - Iraq Dinar
func (*Faker) CurrencyLong ¶
CurrencyLong will generate a random long currency name
Example ¶
Global.Seed(11) fmt.Println(Global.CurrencyLong())
Output: Iraq Dinar
func (*Faker) CurrencyShort ¶
CurrencyShort will generate a random short currency value
Example ¶
Global.Seed(11) fmt.Println(Global.CurrencyShort())
Output: IQD
func (*Faker) Date ¶
Date will generate a random time.Time struct between 1900-Now
Example ¶
Global.Seed(11) fmt.Println(Global.Date().String())
Output: 1900-01-07 04:14:25.685339029 +0000 UTC
func (*Faker) DateCurrentYear ¶
DateCurrentYear will generate a random time.Time within the current year (UTC)
Example ¶
Global.Seed(11) fmt.Println(Global.DateCurrentYear().String())
Output: 2019-06-25 05:16:14.244961305 +0000 UTC
func (*Faker) DateCurrentYearStr ¶
DateCurrentYearStr will generate a random date-time within the current year (UTC) the format is: "2019-01-02 15:04:05.999999999 -0700 MST"
Example ¶
Global.Seed(11) fmt.Println(Global.DateCurrentYearStr())
Output: 2019-06-25 05:16:14.244961305 +0000 UTC
func (*Faker) DateRange ¶
DateRange will generate a random time.Time struct between a start and end date
Example ¶
Global.Seed(11) fmt.Println(Global.DateRange(time.Unix(0, 484633944473634951), time.Unix(0, 1431318744473668209))) // May 10, 1985 years to May 10, 2015
Output: 2012-02-04 14:10:37.166933216 +0000 UTC
func (*Faker) DateStr ¶
DateStr will generate a random date-time between 1900-Now the format is: "2006-01-02 15:04:05.999999999 -0700 MST"
Example ¶
Global.Seed(11) fmt.Println(Global.DateStr())
Output: 1900-01-07 04:14:25.685339029 +0000 UTC
func (*Faker) Day ¶
Day will generate a random day between 1 - 31
Example ¶
Global.Seed(11) fmt.Println(Global.Day())
Output: 12
func (*Faker) Digit ¶
Digit will generate a single ASCII digit
Example ¶
Global.Seed(11) fmt.Println(Global.Digit())
Output: 0
func (*Faker) DomainName ¶
DomainName will generate a random url domain name
Example ¶
Global.Seed(11) fmt.Println(Global.DomainName())
Output: centraltarget.biz
func (*Faker) DomainSuffix ¶
DomainSuffix will generate a random domain suffix
Example ¶
Global.Seed(11) fmt.Println(Global.DomainSuffix())
Output: org
func (*Faker) Email ¶
Email will generate a random email string
Example ¶
Global.Seed(11) fmt.Println(Global.Email())
Output: markusmoen@pagac.net
func (*Faker) Extension ¶
Extension will generate a random file extension
Example ¶
Global.Seed(11) fmt.Println(Global.Extension())
Output: nes
func (*Faker) FirefoxUserAgent ¶
FirefoxUserAgent will generate a random firefox broswer user agent string
Example ¶
Global.Seed(11) fmt.Println(Global.FirefoxUserAgent())
Output: Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10_8_3 rv:7.0) Gecko/1900-07-01 Firefox/37.0
func (*Faker) FirstName ¶
FirstName will generate a random first name
Example ¶
Global.Seed(11) fmt.Println(Global.FirstName())
Output: Markus
func (*Faker) FuelType ¶
FuelType will generate a random fuel type
Example ¶
Global.Seed(11) fmt.Println(Global.FuelType())
Output: CNG
func (*Faker) Gender ¶
Gender will generate a random gender string "male" or "female"
Example ¶
Global.Seed(11) fmt.Println(Global.Gender())
Output: female
func (*Faker) HTTPMethod ¶
HTTPMethod will generate a random http method
Example ¶
Global.Seed(11) fmt.Println(Global.HTTPMethod())
Output: HEAD
func (*Faker) HackerAbbreviation ¶
HackerAbbreviation will return a random hacker abbreviation
Example ¶
Global.Seed(20) fmt.Println(Global.HackerAbbreviation())
Output: AGP
func (*Faker) HackerAdjective ¶
HackerAdjective will return a random hacker adjective
Example ¶
Global.Seed(20) fmt.Println(Global.HackerAdjective())
Output: online
func (*Faker) HackerIngverb ¶
HackerIngverb will return a random hacker ingverb
Example ¶
Global.Seed(20) fmt.Println(Global.HackerIngverb())
Output: navigating
func (*Faker) HackerNoun ¶
HackerNoun will return a random hacker noun
Example ¶
Global.Seed(20) fmt.Println(Global.HackerNoun())
Output: pixel
func (*Faker) HackerPhrase ¶
HackerPhrase will return a random hacker sentence
Example ¶
Global.Seed(20) fmt.Println(Global.HackerPhrase())
Output: Connecting the array won't do anything, we need to generate the haptic COM driver!
func (*Faker) HackerVerb ¶
HackerVerb will return a random hacker verb
Example ¶
Global.Seed(20) fmt.Println(Global.HackerVerb())
Output: connect
func (*Faker) HexColor ¶
HexColor will generate a random hexadecimal color string
Example ¶
Global.Seed(42) fmt.Println(Global.HexColor())
Output: #1b4ef1
func (*Faker) Hexify ¶
Hexify replace all 'h' characters to a random HEX rune
Example ¶
Global.Seed(42) fmt.Println(Global.Hexify("secret:hhhh-hhh"))
Output: secret:1b4e-f15
func (*Faker) HipsterParagraph ¶
func (f *Faker) HipsterParagraph(paragraphCount int, sentenceCount int, wordCount int, separator string) string
HipsterParagraph will generate a random paragraphGenerator Set Paragraph Count Set Sentence Count Set Word Count Set Paragraph Separator
Example ¶
Global.Seed(11) fmt.Println(Global.HipsterParagraph(3, 5, 12, "\n"))
Output: Microdosing roof chia echo pickled meditation cold-pressed raw denim fingerstache normcore sriracha pork belly. Wolf try-hard pop-up blog tilde hashtag health butcher waistcoat paleo portland vinegar. Microdosing sartorial blue bottle slow-carb freegan five dollar toast you probably haven't heard of them asymmetrical chia farm-to-table narwhal banjo. Gluten-free blog authentic literally synth vinyl meh ethical health fixie banh mi Yuccie. Try-hard drinking squid seitan cray VHS echo chillwave hammock kombucha food truck sustainable. Pug bushwick hella tote bag cliche direct trade waistcoat yr waistcoat knausgaard pour-over master. Pitchfork jean shorts franzen flexitarian distillery hella meggings austin knausgaard crucifix wolf heirloom. Crucifix food truck you probably haven't heard of them trust fund fixie gentrify pitchfork stumptown mlkshk umami chambray blue bottle. 3 wolf moon swag +1 biodiesel knausgaard semiotics taxidermy meh artisan hoodie +1 blue bottle. Fashion axe forage mixtape Thundercats pork belly whatever 90's beard selfies chambray cred mlkshk. Shabby chic typewriter VHS readymade lo-fi bitters PBR&B gentrify lomo raw denim freegan put a bird on it. Raw denim cliche dreamcatcher pug fixie park trust fund migas fingerstache sriracha +1 mustache. Tilde shoreditch kickstarter franzen dreamcatcher green juice mustache neutra polaroid stumptown organic schlitz. Flexitarian ramps chicharrones kogi lo-fi mustache tilde forage street church-key williamsburg taxidermy. Chia mustache plaid mumblecore squid slow-carb disrupt Thundercats goth shoreditch master direct trade.
func (*Faker) HipsterParagraphAvg ¶
HipsterParagraphAvg will generate a 4 paragraph separated by Unix new line \n text, each containing 32 Hipster words
Example ¶
Global.Seed(42) fmt.Println(Global.HipsterParagraphAvg())
Output: Gastropub five dollar toast mumblecore kinfolk loko bushwick semiotics pickled tote bag neutra loko tote bag +1 salvia organic umami polaroid synth. Wolf roof PBR&B asymmetrical craft beer taxidermy everyday venmo shabby chic art party marfa flexitarian intelligentsia mumblecore lumbersexual occupy roof you probably haven't heard of them. Kitsch wayfarers hashtag pitchfork shabby chic echo cronut gentrify wolf jean shorts pabst normcore XOXO DIY 3 wolf moon plaid roof fanny pack. Thundercats typewriter deep v literally lo-fi cardigan hammock umami keytar polaroid schlitz yr YOLO sriracha small batch neutra truffaut sustainable. Slow-carb fanny pack neutra wayfarers helvetica polaroid vinegar biodiesel chambray street meh cleanse drinking cliche blog pickled kale chips meggings. Selvage tattooed squid Wes Anderson fanny pack hoodie tofu yr sustainable chillwave slow-carb beard gluten-free carry stumptown hoodie actually williamsburg. Fanny pack austin ethical portland church-key narwhal next level cleanse distillery mixtape deep v humblebrag umami gentrify kogi distillery art party Yuccie. Gentrify tumblr Yuccie VHS humblebrag swag franzen direct trade squid venmo post-ironic chillwave direct trade ethical meh vice post-ironic gentrify.
func (*Faker) HipsterSentence ¶
HipsterSentence will generate a random sentence
Example ¶
Global.Seed(11) fmt.Println(Global.HipsterSentence(5))
Output: Microdosing roof chia echo pickled.
func (*Faker) HipsterSentenceAvg ¶
HipsterSentenceAvg will generate a random sentence containing 18 Hipster words.
Example ¶
Global.Seed(42) fmt.Println(Global.HipsterSentenceAvg())
Output: Gastropub five dollar toast mumblecore kinfolk loko bushwick semiotics pickled tote bag neutra loko tote bag +1 salvia organic umami polaroid synth.
func (*Faker) HipsterWord ¶
HipsterWord will return a single hipster word
Example ¶
Global.Seed(11) fmt.Println(Global.HipsterWord())
Output: microdosing
func (*Faker) Hour ¶
Hour will generate a random hour - in military time
Example ¶
Global.Seed(11) fmt.Println(Global.Hour())
Output: 0
func (*Faker) IPv4Address ¶
IPv4Address will generate a random version 4 ip address
Example ¶
Global.Seed(11) fmt.Println(Global.IPv4Address())
Output: 222.83.191.222
func (*Faker) IPv6Address ¶
IPv6Address will generate a random version 6 ip address
Example ¶
Global.Seed(11) fmt.Println(Global.IPv6Address())
Output: 2001:cafe:8898:ee17:bc35:9064:5866:d019
func (*Faker) ImageURL ¶
ImageURL will generate a random Image Based Upon Height And Width. Images Provided by pipsum.com/
Example ¶
Global.Seed(11) fmt.Println(Global.ImageURL(640, 480))
Output: http://pipsum.com/640x480.jpg
func (*Faker) Job ¶
Job will generate a struct with random job information
Example ¶
Global.Seed(11) jobInfo := Global.Job() fmt.Println(jobInfo.Company) fmt.Println(jobInfo.Title) fmt.Println(jobInfo.Descriptor) fmt.Println(jobInfo.Level)
Output: Moen, Pagac and Wuckert Developer National Integration
func (*Faker) JobDescriptor ¶
JobDescriptor will generate a random job descriptor string
Example ¶
Global.Seed(11) fmt.Println(Global.JobDescriptor())
Output: Central
func (*Faker) JobLevel ¶
JobLevel will generate a random job level string
Example ¶
Global.Seed(11) fmt.Println(Global.JobLevel())
Output: Assurance
func (*Faker) JobTitle ¶
JobTitle will generate a random job title string
Example ¶
Global.Seed(11) fmt.Println(Global.JobTitle())
Output: Director
func (*Faker) LanguageAbbreviation ¶
LanguageAbbreviation will return a random language abbreviation
func (*Faker) LastName ¶
LastName will generate a random last name
Example ¶
Global.Seed(11) fmt.Println(Global.LastName())
Output: Daniel
func (*Faker) Latitude ¶
Latitude will generate a random latitude float64
Example ¶
Global.Seed(11) fmt.Println(Global.Latitude())
Output: -73.53405629980608
func (*Faker) LatitudeInRange ¶
LatitudeInRange will generate a random latitude within the input range
Example ¶
Global.Seed(11) lat, _ := Global.LatitudeInRange(21, 42) fmt.Println(lat)
Output: 22.921026765022624
func (*Faker) Letter ¶
Letter will generate a single random lower case ASCII letter
Example ¶
Global.Seed(11) fmt.Println(Global.Letter())
Output: g
func (*Faker) Lexify ¶
Lexify will replace ? will random generated letters
Example ¶
Global.Seed(11) fmt.Println(Global.Lexify("?????"))
Output: gbrma
func (*Faker) LogLevel ¶
LogLevel will generate a random log level See data/LogLevels for list of available levels
Example ¶
Global.Seed(11) fmt.Println(Global.LogLevel("")) // This will also use general fmt.Println(Global.LogLevel("syslog")) fmt.Println(Global.LogLevel("apache"))
Output: error debug trace1-8
func (*Faker) Longitude ¶
Longitude will generate a random longitude float64
Example ¶
Global.Seed(11) fmt.Println(Global.Longitude())
Output: -147.06811259961216
func (*Faker) LongitudeInRange ¶
LongitudeInRange will generate a random longitude within the input range
Example ¶
Global.Seed(11) long, _ := Global.LongitudeInRange(-10, 10) fmt.Println(long)
Output: -8.170450699978453
func (*Faker) MD5 ¶
Example ¶
Global.Seed(11) fmt.Println(Global.MD5())
Output: 605410f97df9dc83d1e469fb3ee96119
func (*Faker) MacAddress ¶
MacAddress will generate a random mac address
func (*Faker) MimeType ¶
MimeType will generate a random mime file type
Example ¶
Global.Seed(11) fmt.Println(Global.MimeType())
Output: application/dsptype
func (*Faker) Minute ¶
Minute will generate a random minute
Example ¶
Global.Seed(11) fmt.Println(Global.Minute())
Output: 0
func (*Faker) Month ¶
Month will generate a random month string in English (January, February ...)
Example ¶
Global.Seed(11) fmt.Println(Global.Month())
Output: January
func (*Faker) Name ¶
Name will generate a random First and Last Name
Example ¶
Global.Seed(11) fmt.Println(Global.Name())
Output: Markus Moen
func (*Faker) NamePrefix ¶
NamePrefix will generate a random name prefix
Example ¶
Global.Seed(11) fmt.Println(Global.NamePrefix())
Output: Mr.
func (*Faker) NameSuffix ¶
NameSuffix will generate a random name suffix
Example ¶
Global.Seed(11) fmt.Println(Global.NameSuffix())
Output: Jr.
func (*Faker) NanoSecond ¶
NanoSecond will generate a random nano second
Example ¶
Global.Seed(11) fmt.Println(Global.NanoSecond())
Output: 196446360
func (*Faker) Numerify ¶
Numerify will replace # with random numerical values (0-9 digits)
Example ¶
Global.Seed(11) fmt.Println(Global.Numerify("###-###-####"))
Output: 013-645-9948
func (*Faker) OperaUserAgent ¶
OperaUserAgent will generate a random opera browser user agent string
Example ¶
Global.Seed(11) fmt.Println(Global.OperaUserAgent())
Output: Opera/8.39 (Macintosh; U; PPC Mac OS X 10_8_7; en-US) Presto/2.9.335 Version/10.00
func (*Faker) Paragraph ¶
func (f *Faker) Paragraph(paragraphCount int, sentenceCount int, wordCount int, separator string) string
Paragraph will generate a random paragraph, similar with Lorem Lipsum. Set Paragraph Count Set Sentence Count Set Word Count Set Paragraph Separator
Example ¶
Global.Seed(11) fmt.Println(Global.Paragraph(3, 5, 12, "\n"))
Output: Quia quae repellat consequatur quidem nisi quo qui voluptatum accusantium quisquam amet. Quas et ut non dolorem ipsam aut enim assumenda mollitia harum ut. Dicta similique veniam nulla voluptas at excepturi non ad maxime at non. Eaque hic repellat praesentium voluptatem qui consequuntur dolor iusto autem velit aut. Fugit tempore exercitationem harum consequatur voluptatum modi minima aut eaque et et. Aut ea voluptatem dignissimos expedita odit tempore quod aut beatae ipsam iste. Minus voluptatibus dolorem maiores eius sed nihil vel enim odio voluptatem accusamus. Natus quibusdam temporibus tenetur cumque sint necessitatibus dolorem ex ducimus iusto ex. Voluptatem neque dicta explicabo officiis et ducimus sit ut ut praesentium pariatur. Illum molestias nisi at dolore ut voluptatem accusantium et fugiat et ut. Explicabo incidunt reprehenderit non quia dignissimos recusandae vitae soluta quia et quia. Aut veniam voluptas consequatur placeat sapiente non eveniet voluptatibus magni velit eum. Nobis vel repellendus sed est qui autem laudantium quidem quam ullam consequatur. Aut iusto ut commodi similique quae voluptatem atque qui fugiat eum aut. Quis distinctio consequatur voluptatem vel aliquid aut laborum facere officiis iure tempora.
func (*Faker) ParagraphAvg ¶
ParagraphAvg will generate a 4 paragraph separated by Unix new line \n text, each containing 32 words, similar with Lorem Lipsum.
Example ¶
Global.Seed(42) fmt.Println(Global.ParagraphAvg())
Output: At illum ut est sit soluta nulla numquam nobis sunt quaerat ea dolores facere deleniti culpa numquam ut. Distinctio maxime consequatur est qui corporis sunt officia odit et quia odit molestias voluptas porro repellendus magnam ipsa. Corporis eos rem non hic esse optio quisquam hic natus earum molestias iste architecto porro et blanditiis iste. Eum repellendus nostrum qui eius suscipit fugit quia quo et nesciunt quod fuga ut vel pariatur libero sequi. Rerum omnis soluta facilis voluptatem possimus et voluptas eaque possimus harum voluptatibus aperiam voluptatibus qui autem quam veniam. Ea voluptas facilis est autem illum esse amet in id doloribus ab architecto hic at aut aliquam impedit. Id unde et porro est repudiandae omnis beatae iusto pariatur quia sed laboriosam voluptate earum dolores facilis aspernatur. Quam aperiam et nihil explicabo voluptates officia ad porro animi officiis et quam in voluptatem eveniet temporibus fuga.
func (*Faker) Password ¶
func (f *Faker) Password(lower bool, upper bool, numeric bool, special bool, space bool, num int) string
Password will generate a random password Minimum number length of 5 if less than
Example ¶
Global.Seed(11) fmt.Println(Global.Password(true, false, false, false, false, 32)) fmt.Println(Global.Password(false, true, false, false, false, 32)) fmt.Println(Global.Password(false, false, true, false, false, 32)) fmt.Println(Global.Password(false, false, false, true, false, 32)) fmt.Println(Global.Password(true, true, true, true, true, 32)) fmt.Println(Global.Password(true, true, true, true, true, 4))
Output: vodnqxzsuptgehrzylximvylxzoywexw ZSRQWJFJWCSTVGXKYKWMLIAFGFELFJRG 61718615932495608398906260648432 @=-%%#$=-%+++&-#?*&?%&=%?+#@@-&? EEP+wwpk 4lU-eHNXlJZ4n K9%v&TZ9e j ?9X
func (*Faker) PasswordFull ¶
PasswordFull will generate a random password of length 12 that contains at least 1 digit, 1 special character, 1 Lower and 1 Upper case letters.
Example ¶
Global.Seed(42) fmt.Println(Global.PasswordFull())
Output: e+Hea2n9Xw0Q
func (*Faker) Person ¶
func (f *Faker) Person() *PersonInfo
Person will generate a struct with person information
Example ¶
Global.Seed(11) person := Global.Person() job := person.Job address := person.Address contact := person.Contact creditCard := person.CreditCard fmt.Println(person.FirstName) fmt.Println(person.LastName) fmt.Println(person.Gender) fmt.Println(person.SSN) fmt.Println(person.Image) fmt.Println(job.Company) fmt.Println(job.Title) fmt.Println(job.Descriptor) fmt.Println(job.Level) fmt.Println(address.Address) fmt.Println(address.Street) fmt.Println(address.City) fmt.Println(address.State) fmt.Println(address.Zip) fmt.Println(address.Country) fmt.Println(address.Latitude) fmt.Println(address.Longitude) fmt.Println(contact.Phone) fmt.Println(contact.Email) fmt.Println(creditCard.Type) fmt.Println(creditCard.Number) fmt.Println(creditCard.Exp) fmt.Println(creditCard.Cvv)
Output: Markus Moen male 420776036 http://pipsum.com/80x80.jpg Lockman and Sons Developer Global Brand 5369 Streamville, Rossieview, Hawaii 42591 5369 Streamville Rossieview Hawaii 42591 Burkina Faso -6.662594491850811 23.921575244414612 9676941592 christyratke@stracke.org Visa 4027613217148008 11/29 982
func (*Faker) Phone ¶
Phone will generate a 10 digit random phone number string
Example ¶
Global.Seed(11) fmt.Println(Global.Phone())
Output: 7787046119
func (*Faker) PhoneFormatted ¶
PhoneFormatted will generate a random phone number string
Example ¶
Global.Seed(11) fmt.Println(Global.PhoneFormatted())
Output: 136-459-9489
func (*Faker) Price ¶
Price will take in a min and max value and return a formatted price
Example ¶
Global.Seed(11) fmt.Printf("%.2f", Global.Price(0.8618, 1000))
Output: 92.26
func (*Faker) ProgrammingLanguage ¶
ProgrammingLanguage will return a random programming language
func (*Faker) RGBColor ¶
RGBColor will generate a random int slice color
Example ¶
Global.Seed(11) fmt.Println(Global.RGBColor())
Output: [152 23 53]
func (*Faker) RandString ¶
RandString will take in a slice of string and return a randomly selected value
func (*Faker) SHA256 ¶
Example ¶
Global.Seed(11) fmt.Println(Global.SHA256())
Output: e33789b87c2858fbfece97c81533b496493700ff3845d3f80e413ab588859dff
func (*Faker) SSN ¶
SSN will generate a random Social Security Number
Example ¶
Global.Seed(11) fmt.Println(Global.SSN())
Output: 296446360
func (*Faker) SafariUserAgent ¶
SafariUserAgent will generate a random safari browser user agent string
Example ¶
Global.Seed(11) fmt.Println(Global.SafariUserAgent())
Output: Mozilla/5.0 (iPad; CPU OS 8_3_2 like Mac OS X; en-US) AppleWebKit/531.15.6 (KHTML, like Gecko) Version/4.0.5 Mobile/8B120 Safari/6531.15.6
func (*Faker) SafeColor ¶
SafeColor will generate a random safe color string
Example ¶
Global.Seed(11) fmt.Println(Global.SafeColor())
Output: black
func (*Faker) Second ¶
Second will generate a random second
Example ¶
Global.Seed(11) fmt.Println(Global.Second())
Output: 0
func (*Faker) Sentence ¶
Sentence will generate a random sentence, similar with Lorem Lipsum.
Example ¶
Global.Seed(11) fmt.Println(Global.Sentence(5))
Output: Quia quae repellat consequatur quidem.
func (*Faker) SentenceAvg ¶
SentenceAvg will generate a 18 word sentence, similar with Lorem Lipsum.
Example ¶
Global.Seed(42) fmt.Println(Global.SentenceAvg())
Output: At illum ut est sit soluta nulla numquam nobis sunt quaerat ea dolores facere deleniti culpa numquam ut.
func (*Faker) ShuffleStrings ¶
ShuffleStrings will randomize a slice of strings
Example ¶
Global.Seed(11) strings := []string{"happy", "times", "for", "everyone", "have", "a", "good", "day"} Global.ShuffleStrings(strings) fmt.Println(strings)
Output: [good everyone have for times a day happy]
func (*Faker) SimpleStatusCode ¶
SimpleStatusCode will generate a random simple status code
Example ¶
Global.Seed(11) fmt.Println(Global.SimpleStatusCode())
Output: 200
func (*Faker) SliceStrings ¶
func (*Faker) State ¶
State will generate a random state string
Example ¶
Global.Seed(11) fmt.Println(Global.State())
Output: Hawaii
func (*Faker) StateAbr ¶
StateAbr will generate a random abbreviated state string
Example ¶
Global.Seed(11) fmt.Println(Global.StateAbr())
Output: OR
func (*Faker) StatusCode ¶
StatusCode will generate a random status code
Example ¶
Global.Seed(11) fmt.Println(Global.StatusCode())
Output: 404
func (*Faker) Street ¶
Street will generate a random address street string
Example ¶
Global.Seed(11) fmt.Println(Global.Street())
Output: 364 East Rapidsborough
func (*Faker) StreetName ¶
StreetName will generate a random address street name string
Example ¶
Global.Seed(11) fmt.Println(Global.StreetName())
Output: View
func (*Faker) StreetNumber ¶
StreetNumber will generate a random address street number string
Example ¶
Global.Seed(11) fmt.Println(Global.StreetNumber())
Output: 13645
func (*Faker) StreetPrefix ¶
StreetPrefix will generate a random address street prefix string
Example ¶
Global.Seed(11) fmt.Println(Global.StreetPrefix())
Output: Lake
func (*Faker) StreetSuffix ¶
StreetSuffix will generate a random address street suffix string
Example ¶
Global.Seed(11) fmt.Println(Global.StreetSuffix())
Output: land
func (*Faker) Struct ¶
func (f *Faker) Struct(v interface{})
Struct fills in exported elements of a struct with random data based on the value of `fake` tag of exported elements. Use `fake:"skip"` to explicitly skip an element. All built-in types are supported, with templating support for string types. Attention: Because it uses reflection it has a performance penalty!
Example ¶
Global.Seed(42) type Foo struct { //for all the possible template variables see TEMPLATE_VARIABLES.md Browser string `fake:"{browser}"` Drink string `fake:"{beername}"` Phone string `fake:"##-###-###"` Blob string `fake:"?????"` Int int Dice uint8 Pointer *int Skip *string `fake:"skip"` } var f Foo Global.Struct(&f) fmt.Printf("%s\n", f.Browser) fmt.Printf("%s\n", f.Drink) fmt.Printf("%s\n", f.Phone) fmt.Printf("%s\n", f.Blob) fmt.Printf("%d\n", f.Int) fmt.Printf("%d\n", f.Dice) fmt.Printf("%d\n", *f.Pointer) fmt.Printf("%v\n", f.Skip)
Output: firefox Samuel Smith’s Oatmeal Stout 80-357-683 ptneu -4923402592883905764 4 -2620303913143990366 <nil>
func (*Faker) Template ¶
Template replaces all the found variables into the template with the actual results from the Faker.*() function.
fastFaker.Template("Hello {name}!") //Hello Jeromy Schmeler!
All the "#" will be replaced by a digit and all the "?" by a ASCII letter.
To use custom delimiters (instead of {}) see TemplateCustom() For more details and examples see TEMPLATES.md
Example ¶
template := "Hello {name}!" fastFaker := NewFastFaker() // not concurrent safe, see NewSafeFaker() fastFaker.Seed(42) //for each seed value will generate a different result fmt.Printf("%s\n", fastFaker.Template(template)) fmt.Printf("%s\n", fastFaker.Template(template))
Output: Hello Jeromy Schmeler! Hello Kim Steuber!
Example (Html) ¶
template := `<ul class="person"> <li>Name: {name}</li> <li>Age: ##</li> <li>Number: {phone}</li> <li>Address: {street}, {city} {country}</li> </ul>` fastFaker := NewFastFaker() // not concurrent safe, see NewSafeFaker() fastFaker.Seed(42) //for each seed value will generate a different result fmt.Printf("%s\n", fastFaker.Template(template))
Output: <ul class="person"> <li>Name: Kim Steuber</li> <li>Age: 57</li> <li>Number: 9788453650</li> <li>Address: 68397 Rueshire, Port Adams Central African Republic</li> </ul>
Example (Json) ¶
template := `{name:"{name}", age: {digit}, confirmed: {booltext}}` fastFaker := NewFastFaker() // not concurrent safe, see NewSafeFaker() fastFaker.Seed(42) //for each seed value will generate a different result fmt.Printf("%s\n", fastFaker.Template(template))
Output: {name:"Jeromy Schmeler", age: 8, confirmed: false}
Example (Yaml) ¶
template := ` invoice: ###### date: {year}-{month}-{day} bill-to: {username} given: {name} city: {city} state: {state} postal: {zip} product: - sku: ??###? quantity: {uint8} description: {word} price: {uint8}.## tax: {uint8}.## total: {uint16}.##` fastFaker := NewFastFaker() // not concurrent safe, see NewSafeFaker() fastFaker.Seed(42) //for each seed value will generate a different result fmt.Printf("%s\n", fastFaker.Template(template))
Output: invoice: 578035 date: 1995-September-2 bill-to: Little4541 given: Lilly McClure city: Pacochaport state: Arizona postal: 09847 product: - sku: vu768n quantity: 28 description: non price: 75.39 tax: 235.75 total: 61792.82
func (*Faker) TemplateCustom ¶
TemplateCustom replaces all the found variables into the template with the actual results from the Faker.*() function.
fastFaker.Template("Hello {name}!") //Hello Jeromy Schmeler!
It needs a start and end variable delimiters (delimStart, delimEnd). They can only contain runes from TemplateAllowedDelimiters. There is no constraint on the number of characters. Examples of valid delimiters: {{name}}, %%%name%%% or mixed: <<%name>>
It uses Regex to find all the variables.
func (*Faker) TimeZone ¶
TimeZone will select a random timezone string
Example ¶
Global.Seed(11) fmt.Println(Global.TimeZone())
Output: Kaliningrad Standard Time
func (*Faker) TimeZoneAbv ¶
TimeZoneAbv will select a random timezone abbreviation string
Example ¶
Global.Seed(11) fmt.Println(Global.TimeZoneAbv())
Output: KST
func (*Faker) TimeZoneFull ¶
TimeZoneFull will select a random full timezone string
Example ¶
Global.Seed(11) fmt.Println(Global.TimeZoneFull())
Output: (UTC+03:00) Kaliningrad, Minsk
func (*Faker) TimeZoneOffset ¶
TimeZoneOffset will select a random timezone offset
Example ¶
Global.Seed(11) fmt.Println(Global.TimeZoneOffset())
Output: 3
func (*Faker) TransmissionGearType ¶
TransmissionGearType will generate a random transmission type
Example ¶
Global.Seed(11) fmt.Println(Global.TransmissionGearType())
Output: Manual
func (*Faker) URL ¶
URL will generate a random url string
Example ¶
Global.Seed(11) fmt.Println(Global.URL())
Output: https://www.nationalseamless.net/iterate/streamline/systems
func (*Faker) UUID ¶
UUID (version 4) will generate a random unique identifier based upon random numbers Format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
Example ¶
Global.Seed(11) fmt.Println(Global.UUID())
Output: 590c1440-9888-45b0-bd51-a817ee07c3f2
func (*Faker) UserAgent ¶
UserAgent will generate a random browser user agent
Example ¶
Global.Seed(11) fmt.Println(Global.UserAgent())
Output: Mozilla/5.0 (Windows NT 5.0) AppleWebKit/5362 (KHTML, like Gecko) Chrome/37.0.834.0 Mobile Safari/5362
func (*Faker) Username ¶
Username will genrate a random username based upon picking a random lastname and random numbers at the end
Example ¶
Global.Seed(11) fmt.Println(Global.Username())
Output: Daniel1364
func (*Faker) Vehicle ¶
func (f *Faker) Vehicle() *VehicleInfo
Vehicle will generate a struct with vehicle information
Example ¶
Global.Seed(11) vehicle := Global.Vehicle() fmt.Println(vehicle.Brand) fmt.Println(vehicle.Fuel) fmt.Println(vehicle.Model) fmt.Println(vehicle.TransmissionGear) fmt.Println(vehicle.VehicleType) fmt.Println(vehicle.Year)
Output: Fiat Gasoline Freestyle Fwd Automatic Passenger car mini 1925
func (*Faker) VehicleType ¶
VehicleType will generate a random vehicle type string
Example ¶
Global.Seed(11) fmt.Println(Global.VehicleType())
Output: Passenger car mini
func (*Faker) WeekDay ¶
WeekDay will generate a random weekday string (Monday-Sunday)
Example ¶
Global.Seed(11) fmt.Println(Global.WeekDay())
Output: Friday
func (*Faker) Word ¶
Word will generate a random word
Example ¶
Global.Seed(11) fmt.Println(Global.Word())
Output: quia
type PersonInfo ¶
type PersonInfo struct { FirstName string LastName string Gender string SSN string Image string Job *JobInfo Address *AddressInfo Contact *ContactInfo CreditCard *CreditCardInfo }
PersonInfo is a struct of person information
type VehicleInfo ¶
type VehicleInfo struct { // Vehicle type VehicleType string // Fuel type Fuel string // Transmission type TransmissionGear string // Brand name Brand string // Vehicle model Model string // Vehicle model year Year int }
VehicleInfo contains all the major features of a motorized vehicle
Source Files ¶
- address.go
- beer.go
- bool.go
- color.go
- company.go
- contact.go
- currency.go
- datetime.go
- doc.go
- faker.go
- file.go
- hacker.go
- hash.go
- hipster.go
- image.go
- internet.go
- job.go
- languages.go
- log_level.go
- map.go
- misc.go
- name.go
- password.go
- payment.go
- person.go
- status_code.go
- string.go
- struct.go
- templates.go
- templates_variables.go
- unique.go
- user_agent.go
- vehicle.go
- words.go