Documentation
¶
Overview ¶
Package faker is a comprehensive Go library for generating fake data for testing, database seeding, and data anonymization. It provides thread-safe random data generation across various data types including names, addresses, internet data, payments, and more.
Basic Usage:
f := faker.New() name := f.Person().Name() // "John Doe" email := f.Internet().Email() // "john.doe@example.com" phone := f.Phone().Number() // "+1-555-123-4567"
Seeded Generation (for reproducible results):
f := faker.NewWithSeedInt64(12345) name := f.Person().Name() // Always returns the same name for seed 12345
Struct Filling (using struct tags):
type User struct {
Name string `fake:"????????"`
Email string `fake:"??????@??????.com"`
Age int // filled automatically based on field type
}
var user User
f.Struct().Fill(&user)
Pattern characters: # (digit), ? (letter), * (letter or digit). Use fake:"skip" to skip a field, fakesize:"N" for slices/arrays/maps, and RegisterFunction for custom generators via fake:"fn=name".
Performance Characteristics:
- Thread-safe: All Faker instances can be used concurrently - Memory efficient: Uses sync.Pool for frequently allocated objects - Fast generation: Pre-compiled patterns and cached data structures - Supports Go 1.22+ with math/rand/v2 for improved performance
Error Handling:
Most methods in this library are designed to never fail and will return reasonable defaults. Methods that can fail (like file operations) return errors explicitly. For struct filling, invalid tags are ignored silently.
Index ¶
- Constants
- func IsValidEAN13(ean string) bool
- func IsValidISBN13(isbn string) bool
- func IsValidLuhn(number string) bool
- func RandomElement[T any](f Faker, elements ...T) T
- func RandomElementWeighted[T any](f Faker, elements map[int]T) T
- func RandomMapKey[K comparable, V any](f Faker, m map[K]V) K
- func RandomMapValue[K comparable, V any](f Faker, m map[K]V) V
- func RegisterFunction(name string, function fakerFunction)
- func RegisterLocale(data LocaleData)
- func RegisterProvider(name string, fn ProviderFunc)
- func RegisteredProviders() []string
- func Shuffle[T any](slice []T) []T
- func ShuffleWith[T any](f Faker, slice []T) []T
- type Address
- func (a Address) Address() string
- func (a Address) BuildingNumber() (bn string)
- func (a Address) City() string
- func (a Address) CityPrefix() string
- func (a Address) CitySuffix() string
- func (a Address) Country() string
- func (a Address) CountryAbbr() string
- func (a Address) CountryCode() string
- func (a Address) Latitude() (latitude float64)
- func (a Address) Longitude() (longitude float64)
- func (a Address) PostCode() string
- func (a Address) SecondaryAddress() string
- func (a Address) State() string
- func (a Address) StateAbbr() string
- func (a Address) StreetAddress() string
- func (a Address) StreetName() string
- func (a Address) StreetSuffix() string
- type App
- type Barcode
- type Beer
- type BinaryString
- type Blood
- type Boolean
- type Car
- type Color
- func (c Color) CSS() string
- func (c Color) CSSOKLCH() string
- func (c Color) CSSRGBA() string
- func (c Color) ColorName() string
- func (c Color) Hex() string
- func (c Color) OKLCH() string
- func (c Color) OKLCHAsArray() [3]string
- func (c Color) RGB() string
- func (c Color) RGBA() string
- func (c Color) RGBAAsArray() [4]string
- func (c Color) RGBAsArray() [3]string
- func (c Color) SafeColorName() string
- type Company
- type ContactInfo
- type Crypto
- func (c Crypto) Bech32Address() string
- func (c Crypto) Bech32AddressWithLength(length int) string
- func (c Crypto) BitcoinAddress() string
- func (c Crypto) EthereumAddress() string
- func (c Crypto) EtheriumAddress() string
- func (c Crypto) P2PKHAddress() string
- func (c Crypto) P2PKHAddressWithLength(length int) string
- func (c Crypto) P2SHAddress() string
- func (c Crypto) P2SHAddressWithLength(length int) string
- type Currency
- type Directory
- type Emoji
- type Faker
- func (f Faker) Address() Address
- func (f Faker) App() App
- func (f Faker) Asciify(in string) (out string)
- func (f Faker) Barcode() Barcode
- func (f Faker) Beer() Beer
- func (f Faker) BinaryString() BinaryString
- func (f Faker) Blood() Blood
- func (f Faker) Bool() bool
- func (f Faker) BoolWithChance(chanceTrue int) bool
- func (f Faker) Boolean() Boolean
- func (f Faker) Bothify(in string) (out string)
- func (f Faker) Car() Car
- func (f Faker) Color() Color
- func (f Faker) Company() Company
- func (f Faker) Crypto() Crypto
- func (f Faker) Currency() Currency
- func (f Faker) Directory() Directory
- func (f Faker) Emoji() Emoji
- func (f Faker) File() File
- func (f Faker) Float(maxDecimals, minN, maxN int) float64
- func (f Faker) Float32(maxDecimals, minN, maxN int) float32
- func (f Faker) Float64(maxDecimals, minN, maxN int) float64
- func (f Faker) Food() Food
- func (f Faker) Gamer() Gamer
- func (f Faker) Gender() Gender
- func (f Faker) Genre() Genre
- func (f Faker) Hash() Hash
- func (f Faker) Image() Image
- func (f Faker) Int() int
- func (f Faker) Int8() int8
- func (f Faker) Int8Between(minN, maxN int8) int8
- func (f Faker) Int16() int16
- func (f Faker) Int16Between(minN, maxN int16) int16
- func (f Faker) Int32() int32
- func (f Faker) Int32Between(minN, maxN int32) int32
- func (f Faker) Int64() int64
- func (f Faker) Int64Between(minN, maxN int64) int64
- func (f Faker) IntBetween(minN, maxN int) int
- func (f Faker) Internet() Internet
- func (f Faker) Json() Json
- func (f Faker) Language() Language
- func (f Faker) Letter() string
- func (f Faker) Lexify(in string) (out string)
- func (f Faker) Locale() LocaleCode
- func (f Faker) Lorem() Lorem
- func (f Faker) LoremFlickr() LoremFlickr
- func (f Faker) Map() map[string]interface{}
- func (f Faker) MimeType() MimeType
- func (f Faker) Music() Music
- func (f Faker) Numerify(in string) (out string)
- func (f Faker) Payment() Payment
- func (f Faker) Person() Person
- func (f Faker) Pet() Pet
- func (f Faker) Phone() Phone
- func (f Faker) Pokemon() Pokemon
- func (f Faker) ProfileImage() ProfileImage
- func (f Faker) ProgrammingLanguage() ProgrammingLanguage
- func (f Faker) Provider(name string) string
- func (f Faker) RandomDigit() int
- func (f Faker) RandomDigitNot(ignore ...int) int
- func (f Faker) RandomDigitNotNull() int
- func (f Faker) RandomFloat(maxDecimals, minN, maxN int) float64
- func (f Faker) RandomIntElement(a []int) int
- func (f Faker) RandomLetter() string
- func (f Faker) RandomNumber(size int) int
- func (f Faker) RandomStringElement(s []string) string
- func (f Faker) RandomStringMapKey(m map[string]string) string
- func (f Faker) RandomStringMapValue(m map[string]string) string
- func (f Faker) RandomStringWithLength(l int) string
- func (Faker) ShuffleString(s string) string
- func (f Faker) Struct() Struct
- func (f Faker) Time() Time
- func (f Faker) UInt() uint
- func (f Faker) UInt8() uint8
- func (f Faker) UInt8Between(minN, maxN uint8) uint8
- func (f Faker) UInt16() uint16
- func (f Faker) UInt16Between(minN, maxN uint16) uint16
- func (f Faker) UInt32() uint32
- func (f Faker) UInt32Between(minN, maxN uint32) uint32
- func (f Faker) UInt64() uint64
- func (f Faker) UInt64Between(minN, maxN uint64) uint64
- func (f Faker) UIntBetween(minN, maxN uint) uint
- func (f Faker) UUID() UUID
- func (f Faker) Unique() *Unique
- func (f Faker) UserAgent() UserAgent
- func (f Faker) WithLocale(code LocaleCode) Faker
- func (f Faker) YouTube() YouTube
- type File
- type Food
- type Gamer
- type Gender
- type GeneratorInterface
- type Genre
- type HTTPClient
- type HTTPClientImpl
- type Hash
- type Image
- type Internet
- func (i Internet) CompanyEmail() string
- func (i Internet) Domain() string
- func (i Internet) Email() string
- func (i Internet) FreeEmail() string
- func (i Internet) FreeEmailDomain() string
- func (i Internet) HTTPMethod() string
- func (i Internet) Ipv4() string
- func (i Internet) Ipv6() string
- func (i Internet) LocalIpv4() string
- func (i Internet) MacAddress() string
- func (i Internet) Password() string
- func (i Internet) Query() string
- func (i Internet) SafeEmail() string
- func (Internet) SafeEmailDomain() string
- func (i Internet) Slug() string
- func (i Internet) StatusCode() int
- func (i Internet) StatusCodeMessage() string
- func (i Internet) StatusCodeWithMessage() string
- func (i Internet) TLD() string
- func (i Internet) URL() string
- func (i Internet) User() string
- type Json
- type Language
- type LocaleCode
- type LocaleData
- type Lorem
- func (l Lorem) Bytes(maxNbChars int) (out []byte)
- func (l Lorem) Paragraph(nbSentences int) string
- func (l Lorem) Paragraphs(nbParagraph int) []string
- func (l Lorem) Sentence(nbWords int) string
- func (l Lorem) Sentences(nbSentences int) []string
- func (l Lorem) Text(maxNbChars int) string
- func (l Lorem) Word() string
- func (l Lorem) Words(nbWords int) []string
- type LoremFlickr
- type MimeType
- type Music
- type OSResolver
- type OSResolverImpl
- type Payment
- type Person
- func (p Person) Contact() ContactInfo
- func (p Person) DateOfBirth(minAge, maxAge int) time.Time
- func (p Person) FirstName() string
- func (p Person) FirstNameFemale() string
- func (p Person) FirstNameMale() string
- func (p Person) Gender() string
- func (Person) GenderFemale() string
- func (Person) GenderMale() string
- func (p Person) Image() *os.File
- func (p Person) ImageFile() (*os.File, error)
- func (p Person) LastName() string
- func (p Person) Name() string
- func (p Person) NameAndGender() (string, string)
- func (p Person) NameFemale() string
- func (p Person) NameMale() string
- func (p Person) SSN() string
- func (p Person) Suffix() string
- func (p Person) Title() string
- func (Person) TitleFemale() string
- func (Person) TitleMale() string
- type Pet
- type Phone
- type PngEncoder
- type PngEncoderImpl
- type Pokemon
- type ProfileImage
- type ProgrammingLanguage
- type ProviderFunc
- type Struct
- type TempFileCreator
- type TempFileCreatorImpl
- type Time
- func (t Time) ANSIC(max time.Time) string
- func (t Time) AmPm() string
- func (t Time) Century() string
- func (t Time) DayOfMonth() int
- func (t Time) DayOfWeek() time.Weekday
- func (t Time) Future() time.Time
- func (t Time) ISO8601(max time.Time) string
- func (t Time) Kitchen(max time.Time) string
- func (t Time) Month() time.Month
- func (t Time) MonthName() string
- func (t Time) Past() time.Time
- func (t Time) RFC822(max time.Time) string
- func (t Time) RFC822Z(max time.Time) string
- func (t Time) RFC850(max time.Time) string
- func (t Time) RFC1123(max time.Time) string
- func (t Time) RFC1123Z(max time.Time) string
- func (t Time) RFC3339(max time.Time) string
- func (t Time) RFC3339Nano(max time.Time) string
- func (t Time) Recent() time.Time
- func (t Time) RubyDate(max time.Time) string
- func (t Time) Soon() time.Time
- func (t Time) Time(max time.Time) time.Time
- func (t Time) TimeBetween(min, max time.Time) time.Time
- func (t Time) Timezone() string
- func (t Time) Unix(max time.Time) int64
- func (t Time) UnixDate(max time.Time) string
- func (t Time) Year() int
- type UUID
- type Unique
- type UserAgent
- type YouTube
Constants ¶
const ( ABAP = "ABAP" ALGOL = "ALGOL" APL = "APL" ASP = "ASP / ASP.NET" ActionScript = "ActionScript" Ada = "Ada" Alice = "Alice" Assembly = "Assembly Language" Awk = "Awk" BBBasic = "BBC Basic" C = "C" COBOL = "COBOL" CPP = "C++" CSS = "Cascading Style Sheets" CSharp = "C#" D = "D" Delphi = "Delphi" Dreamweaver = "Dreamweaver" Elixir = "Elixir" Erlang = "Erlang" FORTH = "FORTH" FORTRAN = "FORTRAN" FSharp = "F#" Go = "Go" HTML = "HTML" Haskell = "Haskell" IDL = "IDL" INTERCAL = "INTERCAL" Java = "Java" JavaScript = "JavaScript" Jquery = "jQuery" LaTex = "LaTeX" LabVIEW = "LabVIEW" Lisp = "Lisp" Logo = "Logo" ML = "ML" MQL = "MetaQuotes Language" MSAccess = "MS Access" Modula3 = "Modula-3" MySQL = "MySQL" NXTG = "NXT-G" OCaml = "OCaml" ObjectC = "Objective-C" PHP = "PHP" PLI = "PL/I" PLSQL = "PL/SQL" PROLOG = "PROLOG" Pascal = "Pascal" Perl = "Perl" PostScript = "PostScript" PostgreSQL = "PostgreSQL" PureData = "Pure Data" Python = "Python" R = "R" RapidWeaver = "RapidWeaver" RavenDB = "RavenDB" Rexx = "Rexx" Ruby = "Ruby" RubyOnRails = "Ruby on Rails" Rust = "Rust" SAS = "SAS" SGML = "SGML" SMIL = "SMIL" SNOBOL = "SNOBOL" SPlus = "S-PLUS" SQL = "SQL" SSI = "SSI" Scala = "Scala" Sed = "Sed" Shellscript = "Shellscript" Simular = "Simula" Smalltalk = "Smalltalk" Stata = "Stata" Swift = "Swift" TclTk = "Tcl/Tk" UML = "Unified Modeling Language" VHDL = "VHDL" VRML = "VRML" Verilog = "Verilog" VisualBasic = "Visual Basic" VisualFoxPro = "Visual FoxPro" WAPWML = "WAP/WML" XML = "XML" XSL = "XSL" )
Common programming language names
const MaxRecursionDepth = 32
MaxRecursionDepth defines the default maximum depth for recursive structs
Variables ¶
This section is empty.
Functions ¶
func IsValidEAN13 ¶ added in v2.10.0
IsValidEAN13 returns true if the given string is a valid EAN-13.
func IsValidISBN13 ¶ added in v2.10.0
IsValidISBN13 returns true if the given string is a valid ISBN-13.
func IsValidLuhn ¶ added in v2.10.0
IsValidLuhn returns true if the given numeric string passes the Luhn checksum.
func RandomElement ¶ added in v2.2.0
RandomElement returns a fake random element from a given list of elements. Returns the zero value when elements is empty.
func RandomElementWeighted ¶ added in v2.2.0
RandomElementWeighted takes faker instance and a list of elements in the form of map[weight]element, it then selects one of the elements randomly and returns it,
Elements with higher weight have more chance to be returned.
func RandomMapKey ¶ added in v2.4.0
func RandomMapKey[K comparable, V any](f Faker, m map[K]V) K
func RandomMapValue ¶ added in v2.4.0
func RandomMapValue[K comparable, V any](f Faker, m map[K]V) V
func RegisterFunction ¶ added in v2.7.0
func RegisterFunction(name string, function fakerFunction)
func RegisterLocale ¶ added in v2.10.0
func RegisterLocale(data LocaleData)
RegisterLocale adds or replaces locale data for custom locale support.
func RegisterProvider ¶ added in v2.10.0
func RegisterProvider(name string, fn ProviderFunc)
RegisterProvider registers a custom named provider function.
func RegisteredProviders ¶ added in v2.10.0
func RegisteredProviders() []string
RegisteredProviders returns the names of all registered custom providers.
func Shuffle ¶ added in v2.5.0
func Shuffle[T any](slice []T) []T
Shuffle shuffles the slice in place.
func ShuffleWith ¶ added in v2.10.0
ShuffleWith shuffles the slice in place using the Faker's thread-safe random source.
Types ¶
type Address ¶
type Address struct {
Faker *Faker
}
Address is a faker struct for Address
func (Address) BuildingNumber ¶
BuildingNumber returns a fake building number for Address
func (Address) CityPrefix ¶
CityPrefix returns a fake city prefix for Address
func (Address) CitySuffix ¶
CitySuffix returns a fake city suffix for Address
func (Address) CountryAbbr ¶
CountryAbbr returns a fake country abbreviation for Address
func (Address) CountryCode ¶
CountryCode returns a fake country code for Address
func (Address) SecondaryAddress ¶
SecondaryAddress returns a fake secondary address for Address
func (Address) StreetAddress ¶
StreetAddress returns a fake street address for Address
func (Address) StreetName ¶
StreetName returns a fake street name for Address
func (Address) StreetSuffix ¶
StreetSuffix returns a fake street suffix for Address
type Barcode ¶ added in v2.10.0
type Barcode struct {
Faker *Faker
}
Barcode is a faker struct for barcode identifiers.
type Beer ¶
type Beer struct {
Faker *Faker
}
Beer is a faker struct for Beer
type BinaryString ¶
type BinaryString struct {
// contains filtered or unexported fields
}
BinaryString is the faker struct for BinaryString
func (BinaryString) BinaryString ¶
func (bn BinaryString) BinaryString(length int) string
BinaryString returns a random binarystring of given input length
type Boolean ¶
type Boolean struct {
Faker *Faker
}
Boolean is a faker struct for Boolean
func (Boolean) BoolString ¶
BoolString returns a fake bool for string Boolean
func (Boolean) BoolWithChance ¶
BoolWithChance returns true with a given percentual chance that the value is true, otherwise returns false
type Car ¶
type Car struct {
Faker *Faker
}
Car is a faker struct for Car
func (Car) TransmissionGear ¶
TransmissionGear will return a random car transmission gear
type Color ¶
type Color struct {
Faker *Faker
}
Color is a faker struct for Color
func (Color) OKLCHAsArray ¶ added in v2.9.0
OKLCHAsArray returns a fake OKLCH color in array format for Color
func (Color) RGBAAsArray ¶ added in v2.9.0
RGBAAsArray returns a fake rgba color in array format for Color
func (Color) RGBAsArray ¶
RGBAsArray returns a fake rgb color in array format for Color
func (Color) SafeColorName ¶
SafeColorName returns a fake safe color name for Color
type Company ¶
type Company struct {
Faker *Faker
}
Company is a faker struct for Company
func (Company) CatchPhrase ¶
CatchPhrase returns a fake catch phrase for Company
type ContactInfo ¶
ContactInfo struct full of contact info
type Crypto ¶
type Crypto struct {
Faker *Faker
}
Crypto is a faker struct for generating bitcoin data
func (Crypto) Bech32Address ¶
Bech32Address generates a Bech32 bitcoin address Deprecated: Please use BitcoinAddress instead.
func (Crypto) Bech32AddressWithLength ¶
Bech32AddressWithLength generates a Bech32 bitcoin address with specified length. Deprecated: Please use BitcoinAddress instead.
func (Crypto) BitcoinAddress ¶
BitcoinAddress returns an address of either Bech32, P2PKH, or P2SH type.
func (Crypto) EthereumAddress ¶ added in v2.10.0
EthereumAddress returns a hexadecimal ethereum address of 42 characters.
func (Crypto) EtheriumAddress ¶
EtheriumAddress returns a hexadecimal ethereum address of 42 characters.
func (Crypto) P2PKHAddress ¶
P2PKHAddress generates a P2PKH bitcoin address. Deprecated: Please use BitcoinAddress instead.
func (Crypto) P2PKHAddressWithLength ¶
P2PKHAddressWithLength generates a P2PKH bitcoin address with specified length. Deprecated: Please use BitcoinAddress instead.
func (Crypto) P2SHAddress ¶
P2SHAddress generates a P2SH bitcoin address. Deprecated: Please use BitcoinAddress instead.
func (Crypto) P2SHAddressWithLength ¶
P2SHAddressWithLength generates a P2PKH bitcoin address with specified length. Deprecated: Please use BitcoinAddress instead.
type Currency ¶
type Currency struct {
Faker *Faker
}
Currency is a faker struct for generating currency data
func (Currency) CurrencyAndCode ¶
CurrencyAndCode returns a random currency name and currency code
type Directory ¶
type Directory struct {
Faker *Faker
OSResolver OSResolver
}
Directory is a faker struct for Directory
func (Directory) Directory ¶
Directory returns a fake directory path (the directory path style is dependent OS dependent)
func (Directory) DriveLetter ¶
DriveLetter returns a fake Win32 drive letter
func (Directory) UnixDirectory ¶
UnixDirectory returns a fake Unix directory path, regardless of the host OS
func (Directory) WindowsDirectory ¶
WindowsDirectory returns a fake Windows directory path, regardless of the host OS
type Faker ¶
type Faker struct {
Generator GeneratorInterface
// contains filtered or unexported fields
}
Faker is the Generator struct for Faker
func NewWithLocale ¶ added in v2.10.0
func NewWithLocale(code LocaleCode) Faker
NewWithLocale returns a new Faker instance with the given locale.
func NewWithSeed ¶
NewWithSeed returns a new instance of Faker with a given seed
func NewWithSeedInt64 ¶ added in v2.5.0
NewWithSeedInt64 returns a new instance of Faker seeded with the given value
func (Faker) Asciify ¶
Asciify returns a fake string that replaces all "*" characters with random ASCII printable characters. Uses characters from ASCII 97-126 (lowercase letters and symbols). Uses sync.Pool for efficient string building to minimize allocations.
Example:
password := f.Asciify("****-****") // Returns something like "a{7~-b}2@"
func (Faker) BinaryString ¶
func (f Faker) BinaryString() BinaryString
BinaryString returns a fake BinaryString instance for Faker
func (Faker) BoolWithChance ¶
BoolWithChance returns true with a given percentual chance that the value is true, otherwise returns false
func (Faker) Bothify ¶
Bothify returns a fake string that applies both Lexify() and Numerify() transformations. First replaces "?" with letters, then "#" and "%" with numbers.
Example:
serial := f.Bothify("??%#-??##") // Returns something like "ab12-cd34"
func (Faker) Int8Between ¶
Int8Between returns a fake Int8 between a given minimum and maximum values for Faker
func (Faker) Int16Between ¶
Int16Between returns a fake Int16 between a given minimum and maximum values for Faker
func (Faker) Int32Between ¶
Int32Between returns a fake Int32 between a given minimum and maximum values for Faker
func (Faker) Int64Between ¶
Int64Between returns a fake Int64 between a given minimum and maximum values for Faker
func (Faker) IntBetween ¶
IntBetween returns a fake Int between a given minimum and maximum values for Faker
func (Faker) Lexify ¶
Lexify returns a fake string that replaces all "?" characters with random lowercase letters (a-z). Uses sync.Pool for efficient string building to minimize allocations.
Example:
code := f.Lexify("???-???") // Returns something like "abc-xyz"
func (Faker) Locale ¶ added in v2.10.0
func (f Faker) Locale() LocaleCode
Locale returns the active locale code for this Faker instance.
func (Faker) LoremFlickr ¶
func (f Faker) LoremFlickr() LoremFlickr
LoremFlickr returns a fake LoremFlickr instance for Faker
func (Faker) Numerify ¶
Numerify returns a fake string that replaces all "#" characters with random digits (0-9), and all "%" characters with random non-zero digits (1-9). Uses sync.Pool for efficient string building to minimize allocations.
Example:
orderID := f.Numerify("ORD-%###-###") // Returns something like "ORD-1234-567"
func (Faker) ProfileImage ¶
func (f Faker) ProfileImage() ProfileImage
ProfileImage returns a fake ProfileImage instance for Faker
func (Faker) ProgrammingLanguage ¶ added in v2.5.0
func (f Faker) ProgrammingLanguage() ProgrammingLanguage
ProgrammingLanguage returns a fake ProgrammingLanguage instance for Faker
func (Faker) Provider ¶ added in v2.10.0
Provider invokes a registered custom provider by name. Returns an empty string if the provider is not registered.
func (Faker) RandomDigit ¶
RandomDigit returns a fake random digit for Faker
func (Faker) RandomDigitNot ¶
RandomDigitNot returns a fake random digit (0-9) that is not in the list of ignored values. If all digits are ignored, this function will loop indefinitely, so use with caution.
Example:
digit := f.RandomDigitNot(0, 5, 9) // Returns a digit that's not 0, 5, or 9
func (Faker) RandomDigitNotNull ¶
RandomDigitNotNull returns a fake random digit that is not null for Faker
func (Faker) RandomFloat ¶
RandomFloat returns a fake random float number for Faker. maxDecimals: number of decimal places (capped at 10 for performance) minN, maxN: range boundaries (inclusive)
Example:
price := f.RandomFloat(2, 10, 1000) // Returns a float like 123.45 between 10.00 and 1000.00
func (Faker) RandomIntElement ¶
RandomIntElement returns a fake random int element from a given list of ints for Faker. Returns 0 if slice is nil or empty.
func (Faker) RandomLetter ¶
RandomLetter returns a fake random string with a random number of letters for Faker
func (Faker) RandomNumber ¶
RandomNumber returns a fake random integer number for Faker. The size parameter must be positive. If size is invalid, returns a single digit.
func (Faker) RandomStringElement ¶
RandomStringElement returns a fake random string element from a given list of strings for Faker. Returns empty string if slice is nil or empty.
func (Faker) RandomStringMapKey ¶
RandomStringMapKey returns a fake random string key from a given map[string]string for Faker
func (Faker) RandomStringMapValue ¶
RandomStringMapValue returns a fake random string value from a given map[string]string for Faker
func (Faker) RandomStringWithLength ¶
RandomStringWithLength returns a fake random string with the specified length. If length is negative or zero, returns an empty string. If length is excessively large (>1000), caps it at 1000 for performance.
func (Faker) ShuffleString ¶
ShuffleString returns a fake shuffled string from a given string for Faker
func (Faker) UInt8Between ¶
UInt8Between returns a fake UInt8 between a given minimum and maximum values for Faker
func (Faker) UInt16Between ¶
UInt16Between returns a fake UInt16 between a given minimum and maximum values for Faker
func (Faker) UInt32Between ¶
UInt32Between returns a fake UInt32 between a given minimum and maximum values for Faker
func (Faker) UInt64Between ¶
UInt64Between returns a fake UInt64 between a given minimum and maximum values for Faker
func (Faker) UIntBetween ¶
UIntBetween returns a fake UInt between a given minimum and maximum values for Faker
func (Faker) WithLocale ¶ added in v2.10.0
func (f Faker) WithLocale(code LocaleCode) Faker
WithLocale returns a copy of the Faker configured with the given locale.
type File ¶
type File struct {
Faker *Faker
OSResolver OSResolver
}
File is a faker struct for File
func (File) AbsoluteFilePath ¶
AbsoluteFilePath returns a fake absolute path to a fake file (style is dependent on OS). If levels is negative, it defaults to 1.
func (File) AbsoluteFilePathForUnix ¶
AbsoluteFilePathForUnix returns a fake absolute unix-style path to a fake file. If levels is negative, it defaults to 1.
func (File) AbsoluteFilePathForWindows ¶
AbsoluteFilePathForWindows returns a fake absolute win32-style path to a fake file. If levels is negative, it defaults to 1.
func (File) FilenameWithExtension ¶
FilenameWithExtension returns a fake file name with extension
type GeneratorInterface ¶
type GeneratorInterface interface {
Intn(n int) int
Int32n(n int32) int32
Int64n(n int64) int64
Uintn(n uint) uint
Uint32n(n uint32) uint32
Uint64n(n uint64) uint64
Int() int
}
GeneratorInterface presents an Interface that allows us to subsequently control the returned value more accurately when doing tests by allowing us to use a struct that implements these methods to control the returned value. If not in tests, rand.Rand implements these methods and fufills the interface requirements.
type Genre ¶
type Genre struct {
Faker *Faker
}
Genre is a faker struct for Genre
func (Genre) NameWithDescription ¶
NameWithDescription returns a name and description for Genre
type HTTPClient ¶
HTTPClient does HTTP requests to remote servers
type HTTPClientImpl ¶
type HTTPClientImpl struct{}
HTTPClientImpl is the default implementation of HTTPClient
type Hash ¶
type Hash struct {
Faker *Faker
}
Hash is the faker struct for Hashing Functions
type Image ¶
type Image struct {
TempFileCreator TempFileCreator
PngEncoder PngEncoder
// contains filtered or unexported fields
}
Image is a faker struct for Image
type Internet ¶
type Internet struct {
Faker *Faker
}
Internet is a faker struct for Internet
func (Internet) CompanyEmail ¶
CompanyEmail returns a fake company email address for Internet
func (Internet) FreeEmailDomain ¶
FreeEmailDomain returns a fake free email domain for Internet
func (Internet) HTTPMethod ¶
HTTPMethod returns a fake http method for Internet
func (Internet) Ipv6 ¶
Ipv6 returns a fake IPv6 address in full format (8 groups of 4 hex digits). Uses sync.Pool for efficient string building to minimize allocations.
Example:
ipv6 := internet.Ipv6() // Returns something like "2001:0db8:85a3:0000:0000:8a2e:0370:7334"
func (Internet) MacAddress ¶
MacAddress returns a fake MAC address in standard format (6 groups of 2 hex digits). Uses sync.Pool for efficient string building to minimize allocations.
Example:
mac := internet.MacAddress() // Returns something like "2E:03:D1:54:A7:C9"
func (Internet) SafeEmailDomain ¶
SafeEmailDomain returns a fake safe email domain for Internet
func (Internet) StatusCode ¶
StatusCode returns a fake status code for Internet
func (Internet) StatusCodeMessage ¶
StatusCodeMessage returns a fake status code message for Internet
func (Internet) StatusCodeWithMessage ¶
StatusCodeWithMessage returns a fake status code with message for Internet
type Json ¶
type Json struct {
Faker *Faker
}
Json is a faker struct for json files
type Language ¶
type Language struct {
Faker *Faker
}
Language is a faker struct for Language
func (Language) LanguageAbbr ¶
LanguageAbbr returns a fake language name for Language
func (Language) ProgrammingLanguage ¶
ProgrammingLanguage returns a fake programming language for Language
type LocaleCode ¶ added in v2.10.0
type LocaleCode string
LocaleCode identifies a locale for localized data generation.
const ( // LocaleEnUS is the default English (United States) locale. LocaleEnUS LocaleCode = "en_US" // LocaleDeDE is the German (Germany) locale. LocaleDeDE LocaleCode = "de_DE" )
type LocaleData ¶ added in v2.10.0
type LocaleData struct {
Code LocaleCode
FirstNameMale []string
FirstNameFemale []string
LastName []string
}
LocaleData holds localized name data for a locale.
type Lorem ¶
type Lorem struct {
Faker *Faker
}
Lorem is a faker struct for Lorem
func (Lorem) Paragraphs ¶
Paragraphs returns fake paragraphs for Lorem
type LoremFlickr ¶
type LoremFlickr struct {
HTTPClient HTTPClient
TempFileCreator TempFileCreator
// contains filtered or unexported fields
}
LoremFlickr is a faker struct for LoremFlickr
type Music ¶
type Music struct {
Faker *Faker
}
Music is a faker struct for Music
type OSResolver ¶
type OSResolver interface {
OS() string
}
OSResolver returns the GOOS value for operating an operating system
type OSResolverImpl ¶
type OSResolverImpl struct{}
OSResolverImpl is the default implementation of OSResolver
func (OSResolverImpl) OS ¶
func (OSResolverImpl) OS() string
OS returns the runtime.GOOS value for the host operating system
type Payment ¶
type Payment struct {
Faker *Faker
}
Payment is a faker struct for Payment
func (Payment) CreditCardExpirationDateString ¶
CreditCardExpirationDateString returns a fake credit card expiration date in string format (i.e. mm/yy) for Payment
func (Payment) CreditCardNumber ¶
CreditCardNumber returns a Luhn-valid fake credit card number for a random card type.
func (Payment) CreditCardNumberForType ¶ added in v2.10.0
CreditCardNumberForType returns a Luhn-valid fake credit card number for the given card type.
func (Payment) CreditCardType ¶
CreditCardType returns a fake credit card type for Payment
type Person ¶
type Person struct {
Faker *Faker
}
Person is a faker struct for Person
func (Person) Contact ¶
func (p Person) Contact() ContactInfo
Contact will generate a struct with information randomly populated contact information
func (Person) DateOfBirth ¶ added in v2.10.0
DateOfBirth returns a birth date for a person between minAge and maxAge years old.
func (Person) FirstNameFemale ¶
FirstNameFemale returns a fake female first name for Person
func (Person) FirstNameMale ¶
FirstNameMale returns a fake male first name for Person
func (Person) GenderFemale ¶
GenderFemale returns a fake GenderFemale for Person
func (Person) GenderMale ¶
GenderMale returns a fake GenderMale for Person
func (Person) Image ¶
Image return the person profile image. Panics on failure to maintain backward compatibility.
func (Person) ImageFile ¶ added in v2.10.0
ImageFile return the person profile image without panicking on errors.
func (Person) NameAndGender ¶
NameAndGender returns a fake NameAndGender for Person
func (Person) NameFemale ¶
NameFemale returns a fake NameFemale for Person
func (Person) TitleFemale ¶
TitleFemale returns a fake female title for Person
type Phone ¶
type Phone struct {
Faker *Faker
}
Phone is a faker struct for Phone
func (Phone) E164Number ¶
E164Number returns a fake E164 phone number for Phone
func (Phone) ExchangeCode ¶
ExchangeCode returns a fake exchange code for Phone
func (Phone) TollFreeAreaCode ¶
TollFreeAreaCode returns a fake toll free area code for Phone
func (Phone) TollFreeNumber ¶ added in v2.10.0
TollFreeNumber returns a fake toll free number for Phone.
func (Phone) ToolFreeNumber ¶
ToolFreeNumber returns a fake toll free number for Phone
type PngEncoder ¶
PngEncoder encodes a image.Image to a io.Writer
type PngEncoderImpl ¶
type PngEncoderImpl struct{}
PngEncoderImpl is the default implementation of the PngEncoder
type Pokemon ¶ added in v2.5.0
type Pokemon struct {
Faker *Faker
}
Pokemon is a faker struct for Pokemon
type ProfileImage ¶
type ProfileImage struct {
HTTPClient HTTPClient
TempFileCreator TempFileCreator
// contains filtered or unexported fields
}
ProfileImage is a faker struct for ProfileImage
func (ProfileImage) Image ¶
func (pi ProfileImage) Image() *os.File
Image generates a *os.File with a random profile image using the randomuser.me service. Panics on failure to maintain backward compatibility.
type ProgrammingLanguage ¶ added in v2.5.0
type ProgrammingLanguage struct {
Faker *Faker
}
ProgrammingLanguage is a faker struct for ProgrammingLanguage
func (ProgrammingLanguage) Name ¶ added in v2.5.0
func (pl ProgrammingLanguage) Name() string
Name returns a random programming language name
func (ProgrammingLanguage) VariableName ¶ added in v2.5.0
func (pl ProgrammingLanguage) VariableName() string
VariableName generates a random valid programming language identifier
func (ProgrammingLanguage) VariableNameWithLength ¶ added in v2.5.0
func (pl ProgrammingLanguage) VariableNameWithLength(length int) string
VariableNameWithLength generates a random valid programming language identifier with the specified length
func (ProgrammingLanguage) Version ¶ added in v2.5.0
func (pl ProgrammingLanguage) Version(language string) string
Version returns a random version for the given language
type ProviderFunc ¶ added in v2.10.0
ProviderFunc generates a string value using the given Faker instance.
type Struct ¶
type Struct struct {
Faker *Faker
}
Struct is a faker struct for generating random data for struct fields
func (Struct) Fill ¶
func (s Struct) Fill(v interface{})
Fill populates a struct with random data based on its type and tags
func (Struct) FillWithDepth ¶ added in v2.4.0
type TempFileCreator ¶
TempFileCreator creates temporary files
type TempFileCreatorImpl ¶
type TempFileCreatorImpl struct{}
TempFileCreatorImpl is the default implementation of TempFileCreator
type Time ¶
type Time struct {
Faker *Faker
}
Time is a faker struct for Time
func (Time) DayOfMonth ¶
DayOfMonth returns a fake day of month for Time
func (Time) RFC3339Nano ¶
RFC3339Nano returns a fake time in RFC3339Nano format for Time
func (Time) TimeBetween ¶
TimeBetween returns a fake time between for Time
type Unique ¶ added in v2.10.0
type Unique struct {
Faker *Faker
// contains filtered or unexported fields
}
Unique provides unique value generation, avoiding duplicates within a single Unique instance.
func (*Unique) IntBetween ¶ added in v2.10.0
IntBetween returns a unique int between minN and maxN inclusive.
func (*Unique) Reset ¶ added in v2.10.0
func (u *Unique) Reset()
Reset clears all tracked unique values.
func (*Unique) StringElement ¶ added in v2.10.0
StringElement returns a unique element from the given slice.
type UserAgent ¶
type UserAgent struct {
Faker *Faker
}
UserAgent is a faker struct for UserAgent
func (UserAgent) InternetExplorer ¶
InternetExplorer returns a fake internet explorer UserAgent
type YouTube ¶
type YouTube struct {
Faker *Faker
}
YouTube is a faker struct for YouTube
func (YouTube) GenerateEmbededURL ¶
GenerateEmbededURL returns a fake embedded youtube video url
func (YouTube) GenerateFullURL ¶
GenerateFullURL returns a fake standard youtube video url
func (YouTube) GenerateShareURL ¶
GenerateShareURL returns a fake share youtube video url
func (YouTube) GenerateVideoID ¶
GenerateVideoID returns a youtube video id
Source Files
¶
- address.go
- app.go
- barcode.go
- beer.go
- binarystring.go
- blood.go
- boolean.go
- car.go
- color.go
- company.go
- crypto.go
- currency.go
- directory.go
- emoji.go
- english_words.go
- faker.go
- file.go
- food.go
- gamer.go
- gender.go
- genre.go
- hash.go
- iban.go
- image.go
- internet.go
- json.go
- language.go
- locale.go
- locale_de.go
- lorem.go
- lorem_flickr.go
- mimetype.go
- music.go
- payment.go
- person.go
- pet.go
- phone.go
- pokemon.go
- profile_image.go
- programming_language.go
- provider.go
- random_element.go
- struct.go
- time.go
- unique.go
- user_agent.go
- utils.go
- uuid.go
- youtube.go