faker

package module
v2.3.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 29, 2024 License: MIT Imports: 24 Imported by: 25

README

Faker is a Go library that generates fake data for you. Whether you need to bootstrap your database, create good-looking XML documents, fill-in your persistence to stress test it, or anonymize data taken from a production service, Faker is for you.

Faker is heavily inspired by PHP"s Faker

Faker requires Go >= 1.11 and < 1.20 for 1.X and Go >= 1.20 for 2.X

PkgGoDev Test codecov Go Report Card Codacy Badge CodeFactor Release Gitpod ready-to-code Hits

Test it directly from your browser

Start at https://play.golang.org/p/JpTagDGBaHK

Installation

Add this to your Go file

import "github.com/jaswdr/faker/v2"

And run go get or dep ensure to get the package.

Basic Usage

Use faker.New() to create and initialize a faker generator, which can generate data by accessing properties named after the type of data you want.

import "github.com/jaswdr/faker/v2"

func main() {
    fake := faker.New()

    fake.Person().Name()
    // Lucy Cechtelar

    fake.Address().Address()
    // 426 Jordy Lodge

    fake.Lorem().Text(100)
    // Dolores sit sint laboriosam dolorem culpa et autem. Beatae nam sunt fugit
    // et sit et mollitia sed.
    // Fuga deserunt tempora facere magni omnis. Omnis quia temporibus laudantium
    // sit minima sint.
}

Even if this example shows a method access, each call to fake.Name() yields a different (random) result.

p := fake.Person()

for i:=0; i < 10; i++ {
  fmt.Println(p.Name())
}
  // Adaline Reichel
  // Dr. Santa Prosacco DVM
  // Noemy Vandervort V
  // Lexi O"Conner
  // Gracie Weber
  // Roscoe Johns
  // Emmett Lebsack
  // Keegan Thiel
  // Wellington Koelpin II
  // Ms. Karley Kiehn V

You can also generate a profile image.

image := p.Image()

fmt.Println(image.Name())
// /tmp/profil-picture-img-1064677774.jfif

fmt.Printf("%+v", image)
// &{file:0xc0002e4300}

Generate fake data using Structs

type ExampleStruct struct {
	SimpleStringField string
	SimpleNumber int
	SimpleBool bool
	SomeFormatedString string `fake:"??? ###"`
	SomeStringArray [5]string `fake:"????"`
}

example := ExampleStruct{}
f.Struct().Fill(&example)
fmt.Printf("%+v", example)
//{SimpleStringField:87576a01c2a547b2bbf9b7c736d1db40 SimpleNumber:9223372036854775807 SimpleBool:false SomeFormatedString:cxo 321 SomeStringArray:[effr swxp ldnj obcs nvlg]}

Generate random placeholder images using LoremFlickr

// get a *os.File pointing to a file that is a random image
image := f.LoremFlickr().Image(100, 100, []string{}, "", false)

fmt.Println(image.Name())
// /tmp/loremflickr-img-4101493944.jpg

Generate profile images using ThisPersonDoesNotExist

profileImage := f.ProfileImage().Image()

fmt.Println(profileImage.Name())
// /tmp/profil-picture-img-4022222298.jfif

See more formatters in docs

Development

Create a fork and get the code.

$ go get github.com/jaswdr/faker/v2

Do your changes, add tests, run the tests.

$ go test
PASS
ok      github.com/jaswdr/faker/v2 2.966s

Push to your fork and send a new pull request from your fork to this repository.

Versioning

Faker is maintained under the Semantic Versioning guidelines. Starting at 2.X, we only support maintained versions of Go. Which according to Go's Release Policy means that we only support the two newer major versions.

License

Faker is released under the MIT Licence. See the bundled LICENSE file for details.

Maintainer

Created and maitained by Jonathan Schweder (@jaswdr) and many others

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RandomElement added in v2.2.0

func RandomElement[T any](f Faker, elements ...T) T

RandomElement returns a fake random element from a given list of elements

func RandomElementWeighted added in v2.2.0

func RandomElementWeighted[T any](f Faker, elements map[int]T) T

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.

Types

type Address

type Address struct {
	Faker *Faker
}

Address is a faker struct for Address

func (Address) Address

func (a Address) Address() string

Address returns a fake Address

func (Address) BuildingNumber

func (a Address) BuildingNumber() (bn string)

BuildingNumber returns a fake building number for Address

func (Address) City

func (a Address) City() string

City returns a fake city for Address

func (Address) CityPrefix

func (a Address) CityPrefix() string

CityPrefix returns a fake city prefix for Address

func (Address) CitySuffix

func (a Address) CitySuffix() string

CitySuffix returns a fake city suffix for Address

func (Address) Country

func (a Address) Country() string

Country returns a fake country for Address

func (Address) CountryAbbr

func (a Address) CountryAbbr() string

CountryAbbr returns a fake country abbreviation for Address

func (Address) CountryCode

func (a Address) CountryCode() string

CountryCode returns a fake country code for Address

func (Address) Latitude

func (a Address) Latitude() (latitude float64)

Latitude returns a fake latitude for Address

func (Address) Longitude

func (a Address) Longitude() (longitude float64)

Longitude returns a fake longitude for Address

func (Address) PostCode

func (a Address) PostCode() string

PostCode returns a fake postal code for Address

func (Address) SecondaryAddress

func (a Address) SecondaryAddress() string

SecondaryAddress returns a fake secondary address for Address

func (Address) State

func (a Address) State() string

State returns a fake state for Address

func (Address) StateAbbr

func (a Address) StateAbbr() string

StateAbbr returns a fake state abbreviation for Address

func (Address) StreetAddress

func (a Address) StreetAddress() string

StreetAddress returns a fake street address for Address

func (Address) StreetName

func (a Address) StreetName() string

StreetName returns a fake street name for Address

func (Address) StreetSuffix

func (a Address) StreetSuffix() string

StreetSuffix returns a fake street suffix for Address

type App

type App struct {
	Faker *Faker
}

App is a faker struct for App

func (App) Name

func (a App) Name() string

Name returns a fake app name for App

func (App) Version

func (a App) Version() string

Version returns a fake app version for App

type Beer

type Beer struct {
	Faker *Faker
}

Beer is a faker struct for Beer

func (Beer) Alcohol

func (b Beer) Alcohol() string

Alcohol will return a random beer alcohol level between 2.0 and 10.0

func (Beer) Blg

func (b Beer) Blg() string

Blg will return a random beer blg between 5.0 and 20.0

func (Beer) Hop

func (b Beer) Hop() string

Hop will return a random beer hop

func (Beer) Ibu

func (b Beer) Ibu() string

Ibu will return a random beer ibu value between 10 and 100

func (Beer) Malt

func (b Beer) Malt() string

Malt will return a random beer malt

func (Beer) Name

func (b Beer) Name() string

Name will return a random beer name

func (Beer) Style

func (b Beer) Style() string

Style will return a random beer style

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 Blood

type Blood struct {
	Faker *Faker
}

Blood is a faker struct for Blood

func (Blood) Name

func (f Blood) Name() string

Name returns a Blood name for Blood

type Boolean

type Boolean struct {
	Faker *Faker
}

Boolean is a faker struct for Boolean

func (Boolean) Bool

func (b Boolean) Bool() bool

Bool returns a fake bool for Faker

func (Boolean) BoolInt

func (b Boolean) BoolInt() int

BoolInt returns a fake bool for Integer Boolean

func (Boolean) BoolString

func (b Boolean) BoolString(firstArg, secondArg string) string

BoolString returns a fake bool for string Boolean

func (Boolean) BoolWithChance

func (b Boolean) BoolWithChance(chanceTrue int) bool

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) Category

func (c Car) Category() string

Category will return a random car category

func (Car) FuelType

func (c Car) FuelType() string

FuelType will return a random car fuel type

func (Car) Maker

func (c Car) Maker() string

Maker will return a random car maker

func (Car) Model

func (c Car) Model() string

Model will return a random car model

func (Car) Plate

func (c Car) Plate() string

Plate will return a random car plate

func (Car) TransmissionGear

func (c Car) TransmissionGear() string

TransmissionGear will return a random car transmission gear

type Color

type Color struct {
	Faker *Faker
}

Color is a faker struct for Color

func (Color) CSS

func (c Color) CSS() string

CSS returns a fake color in CSS format for Color

func (Color) ColorName

func (c Color) ColorName() string

ColorName returns a fake color name for Color

func (Color) Hex

func (c Color) Hex() string

Hex returns a fake hex for Color

func (Color) RGB

func (c Color) RGB() string

RGB returns a fake rgb for Color

func (Color) RGBAsArray

func (c Color) RGBAsArray() [3]string

RGBAsArray returns a fake rgb color in array format for Color

func (Color) SafeColorName

func (c Color) SafeColorName() string

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) BS

func (c Company) BS() string

BS returns a fake bs words for Company

func (Company) CatchPhrase

func (c Company) CatchPhrase() string

CatchPhrase returns a fake catch phrase for Company

func (Company) EIN

func (c Company) EIN() int

EIN returns a fake EIN codes for Company

func (Company) JobTitle

func (c Company) JobTitle() string

JobTitle returns a fake job title for Company

func (Company) Name

func (c Company) Name() string

Name returns a fake name for Company

func (Company) Suffix

func (c Company) Suffix() string

Suffix returns a fake suffix for Company

type ContactInfo

type ContactInfo struct {
	Phone string
	Email string
}

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

func (c Crypto) Bech32Address() string

Bech32Address generates a Bech32 bitcoin address Deprecated: Please use BitcoinAddress instead.

func (Crypto) Bech32AddressWithLength

func (c Crypto) Bech32AddressWithLength(length int) string

Bech32AddressWithLength generates a Bech32 bitcoin address with specified length. Deprecated: Please use BitcoinAddress instead.

func (Crypto) BitcoinAddress

func (c Crypto) BitcoinAddress() string

BitcoinAddress returns an address of either Bech32, P2PKH, or P2SH type.

func (Crypto) EtheriumAddress

func (c Crypto) EtheriumAddress() string

EtheriumAddress returns a hexadecimal ethereum address of 42 characters.

func (Crypto) P2PKHAddress

func (c Crypto) P2PKHAddress() string

P2PKHAddress generates a P2PKH bitcoin address. Deprecated: Please use BitcoinAddress instead.

func (Crypto) P2PKHAddressWithLength

func (c Crypto) P2PKHAddressWithLength(length int) string

P2PKHAddressWithLength generates a P2PKH bitcoin address with specified length. Deprecated: Please use BitcoinAddress instead.

func (Crypto) P2SHAddress

func (c Crypto) P2SHAddress() string

P2SHAddress generates a P2SH bitcoin address. Deprecated: Please use BitcoinAddress instead.

func (Crypto) P2SHAddressWithLength

func (c Crypto) P2SHAddressWithLength(length int) string

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) Code

func (c Currency) Code() string

Code returns a random currency code

func (Currency) Country

func (c Currency) Country() string

Country returns a random currency country

func (Currency) Currency

func (c Currency) Currency() string

Currency returns a random currency name

func (Currency) CurrencyAndCode

func (c Currency) CurrencyAndCode() (string, string)

CurrencyAndCode returns a random currency name and currency code

func (Currency) Number

func (c Currency) Number() int

Number returns a random currency number

type Directory

type Directory struct {
	Faker      *Faker
	OSResolver OSResolver
}

Directory is a faker struct for Directory

func (Directory) Directory

func (d Directory) Directory(levels int) string

Directory returns a fake directory path (the directory path style is dependent OS dependent)

func (Directory) DriveLetter

func (d Directory) DriveLetter() string

DriveLetter returns a fake Win32 drive letter

func (Directory) UnixDirectory

func (d Directory) UnixDirectory(levels int) string

UnixDirectory returns a fake Unix directory path, regardless of the host OS

func (Directory) WindowsDirectory

func (d Directory) WindowsDirectory(levels int) string

WindowsDirectory returns a fake Windows directory path, regardless of the host OS

type Emoji

type Emoji struct {
	Faker *Faker
}

Emoji is a faker struct for Emoji

func (Emoji) Emoji

func (a Emoji) Emoji() string

Emoji returns a fake emoji for Emoji

func (Emoji) EmojiCode

func (a Emoji) EmojiCode() string

EmojiCode returns a fake emoji for Emoji

type Faker

type Faker struct {
	Generator GeneratorInterface
}

Faker is the Generator struct for Faker

func New

func New() (f Faker)

New returns a new instance of Faker instance with a random seed

func NewWithSeed

func NewWithSeed(src rand.Source) (f Faker)

NewWithSeed returns a new instance of Faker instance with a given seed

func (Faker) Address

func (f Faker) Address() Address

Address returns a fake Address instance for Faker

func (Faker) App

func (f Faker) App() App

App returns a fake App instance for Faker

func (Faker) Asciify

func (f Faker) Asciify(in string) (out string)

Asciify returns a fake string that replace all "*" characters with random ASCII values from a given string for Faker

func (Faker) Beer

func (f Faker) Beer() Beer

Beer returns a fake Beer instance for Faker

func (Faker) BinaryString

func (f Faker) BinaryString() BinaryString

BinaryString returns a fake BinaryString instance for Faker

func (Faker) Blood

func (f Faker) Blood() Blood

Blood returns a fake Blood instance for Faker

func (Faker) Bool

func (f Faker) Bool() bool

Bool returns a fake bool for Faker

func (Faker) BoolWithChance

func (f Faker) BoolWithChance(chanceTrue int) bool

BoolWithChance returns true with a given percentual chance that the value is true, otherwise returns false

func (Faker) Boolean

func (f Faker) Boolean() Boolean

Boolean returns a fake Boolean instance for Faker

func (Faker) Bothify

func (f Faker) Bothify(in string) (out string)

Bothify returns a fake string that apply Lexify() and Numerify() on a given string for Faker

func (Faker) Car

func (f Faker) Car() Car

Car returns a fake Car instance for Faker

func (Faker) Color

func (f Faker) Color() Color

Color returns a fake Color instance for Faker

func (Faker) Company

func (f Faker) Company() Company

Company returns a fake Company instance for Faker

func (Faker) Crypto

func (f Faker) Crypto() Crypto

Crypto returns a fake Crypto instance for Faker

func (Faker) Currency

func (f Faker) Currency() Currency

Currency returns a fake Currency instance for Faker

func (Faker) Directory

func (f Faker) Directory() Directory

Directory returns a fake Directory instance for Faker

func (Faker) Emoji

func (f Faker) Emoji() Emoji

Emoji returns a fake Emoji instance for Faker

func (Faker) File

func (f Faker) File() File

File returns a fake File instance for Faker

func (Faker) Float

func (f Faker) Float(maxDecimals, min, max int) float64

Float returns a fake random float number for Faker

func (Faker) Float32

func (f Faker) Float32(maxDecimals, min, max int) float32

Float32 returns a fake random float32 number for Faker

func (Faker) Float64

func (f Faker) Float64(maxDecimals, min, max int) float64

Float64 returns a fake random float64 number for Faker

func (Faker) Food

func (f Faker) Food() Food

Food returns a fake Food instance for Faker

func (Faker) Gamer

func (f Faker) Gamer() Gamer

Gamer returns a fake Gamer instance for Faker

func (Faker) Gender

func (f Faker) Gender() Gender

Gender returns a fake Gender instance for Faker

func (Faker) Genre

func (f Faker) Genre() Genre

Genre returns a fake Genre instance for Faker

func (Faker) Hash

func (f Faker) Hash() Hash

Hash returns a fake Hash instance for Faker

func (Faker) Image

func (f Faker) Image() Image

Image returns a fake Image instance for Faker

func (Faker) Int

func (f Faker) Int() int

Int returns a fake Int number for Faker

func (Faker) Int16

func (f Faker) Int16() int16

Int16 returns a fake Int16 number for Faker

func (Faker) Int16Between

func (f Faker) Int16Between(min, max int16) int16

Int16Between returns a fake Int16 between a given minimum and maximum values for Faker

func (Faker) Int32

func (f Faker) Int32() int32

Int32 returns a fake Int32 number for Faker

func (Faker) Int32Between

func (f Faker) Int32Between(min, max int32) int32

Int32Between returns a fake Int32 between a given minimum and maximum values for Faker

func (Faker) Int64

func (f Faker) Int64() int64

Int64 returns a fake Int64 number for Faker

func (Faker) Int64Between

func (f Faker) Int64Between(min, max int64) int64

Int64Between returns a fake Int64 between a given minimum and maximum values for Faker

func (Faker) Int8

func (f Faker) Int8() int8

Int8 returns a fake Int8 number for Faker

func (Faker) Int8Between

func (f Faker) Int8Between(min, max int8) int8

Int8Between returns a fake Int8 between a given minimum and maximum values for Faker

func (Faker) IntBetween

func (f Faker) IntBetween(min, max int) int

IntBetween returns a fake Int between a given minimum and maximum values for Faker

func (Faker) Internet

func (f Faker) Internet() Internet

Internet returns a fake Internet instance for Faker

func (Faker) Json

func (f Faker) Json() Json

Json returns a fake Json instance for Faker

func (Faker) Language

func (f Faker) Language() Language

Language returns a fake Language instance for Faker

func (Faker) Letter

func (f Faker) Letter() string

Letter returns a fake single letter for Faker

func (Faker) Lexify

func (f Faker) Lexify(in string) (out string)

Lexify returns a fake string that replace all "?" characters with random letters from a given string for Faker

func (Faker) Lorem

func (f Faker) Lorem() Lorem

Lorem returns a fake Lorem instance for Faker

func (Faker) LoremFlickr

func (f Faker) LoremFlickr() LoremFlickr

LoremFlickr returns a fake LoremFlickr instance for Faker

func (Faker) Map

func (f Faker) Map() map[string]interface{}

Map returns a fake Map instance for Faker

func (Faker) MimeType

func (f Faker) MimeType() MimeType

MimeType returns a fake MimeType instance for Faker

func (Faker) Music

func (f Faker) Music() Music

Music returns a fake Music instance for Faker

func (Faker) Numerify

func (f Faker) Numerify(in string) (out string)

Numerify returns a fake string that replace all "#" characters with numbers from a given string for Faker

func (Faker) Payment

func (f Faker) Payment() Payment

Payment returns a fake Payment instance for Faker

func (Faker) Person

func (f Faker) Person() Person

Person returns a fake Person instance for Faker

func (Faker) Pet

func (f Faker) Pet() Pet

Pet returns a fake Pet instance for Faker

func (Faker) Phone

func (f Faker) Phone() Phone

Phone returns a fake Phone instance for Faker

func (Faker) ProfileImage

func (f Faker) ProfileImage() ProfileImage

ProfileImage returns a fake ProfileImage instance for Faker

func (Faker) RandomDigit

func (f Faker) RandomDigit() int

RandomDigit returns a fake random digit for Faker

func (Faker) RandomDigitNot

func (f Faker) RandomDigitNot(ignore ...int) int

RandomDigitNot returns a fake random digit for Faker that is not in a list of ignored

func (Faker) RandomDigitNotNull

func (f Faker) RandomDigitNotNull() int

RandomDigitNotNull returns a fake random digit that is not null for Faker

func (Faker) RandomFloat

func (f Faker) RandomFloat(maxDecimals, min, max int) float64

RandomFloat returns a fake random float number for Faker

func (Faker) RandomIntElement

func (f Faker) RandomIntElement(a []int) int

RandomIntElement returns a fake random int element form a given list of ints for Faker

func (Faker) RandomLetter

func (f Faker) RandomLetter() string

RandomLetter returns a fake random string with a random number of letters for Faker

func (Faker) RandomNumber

func (f Faker) RandomNumber(size int) int

RandomNumber returns a fake random integer number for Faker

func (Faker) RandomStringElement

func (f Faker) RandomStringElement(s []string) string

RandomStringElement returns a fake random string element from a given list of strings for Faker

func (Faker) RandomStringMapKey

func (f Faker) RandomStringMapKey(m map[string]string) string

RandomStringMapKey returns a fake random string key from a given map[string]string for Faker

func (Faker) RandomStringMapValue

func (f Faker) RandomStringMapValue(m map[string]string) string

RandomStringMapValue returns a fake random string value from a given map[string]string for Faker

func (Faker) RandomStringWithLength

func (f Faker) RandomStringWithLength(l int) string

func (Faker) ShuffleString

func (Faker) ShuffleString(s string) string

ShuffleString returns a fake shuffled string from a given string for Faker

func (Faker) Struct

func (f Faker) Struct() Struct

Struct returns a fake Struct instance for Faker

func (Faker) Time

func (f Faker) Time() Time

Time returns a fake Time instance for Faker

func (Faker) UInt

func (f Faker) UInt() uint

UInt returns a fake UInt number for Faker

func (Faker) UInt16

func (f Faker) UInt16() uint16

UInt16 returns a fake UInt16 number for Faker

func (Faker) UInt16Between

func (f Faker) UInt16Between(min, max uint16) uint16

UInt16Between returns a fake UInt16 between a given minimum and maximum values for Faker

func (Faker) UInt32

func (f Faker) UInt32() uint32

UInt32 returns a fake UInt32 number for Faker

func (Faker) UInt32Between

func (f Faker) UInt32Between(min, max uint32) uint32

UInt32Between returns a fake UInt32 between a given minimum and maximum values for Faker

func (Faker) UInt64

func (f Faker) UInt64() uint64

UInt64 returns a fake UInt64 number for Faker

func (Faker) UInt64Between

func (f Faker) UInt64Between(min, max uint64) uint64

UInt64Between returns a fake UInt64 between a given minimum and maximum values for Faker

func (Faker) UInt8

func (f Faker) UInt8() uint8

UInt8 returns a fake UInt8 number for Faker

func (Faker) UInt8Between

func (f Faker) UInt8Between(min, max uint8) uint8

UInt8Between returns a fake UInt8 between a given minimum and maximum values for Faker

func (Faker) UIntBetween

func (f Faker) UIntBetween(min, max uint) uint

UIntBetween returns a fake UInt between a given minimum and maximum values for Faker

func (Faker) UUID

func (f Faker) UUID() UUID

UUID returns a fake UUID instance for Faker

func (Faker) UserAgent

func (f Faker) UserAgent() UserAgent

UserAgent returns a fake UserAgent instance for Faker

func (Faker) YouTube

func (f Faker) YouTube() YouTube

YouTube returns a fake YouTube instance for Faker

type File

type File struct {
	Faker      *Faker
	OSResolver OSResolver
}

File is a faker struct for File

func (File) AbsoluteFilePath

func (f File) AbsoluteFilePath(levels int) string

AbsoluteFilePath returns a fake absolute path to a fake file (style is dependent on OS)

func (File) AbsoluteFilePathForUnix

func (f File) AbsoluteFilePathForUnix(levels int) string

AbsoluteFilePathForUnix returns a fake absolute unix-style path to a fake file

func (File) AbsoluteFilePathForWindows

func (f File) AbsoluteFilePathForWindows(levels int) string

AbsoluteFilePathForWindows returns a fake absolute win32-style path to a fake file

func (File) Extension

func (f File) Extension() string

Extension returns a fake Extension file

func (File) FilenameWithExtension

func (f File) FilenameWithExtension() string

FilenameWithExtension returns a fake file name with extension

type Food

type Food struct {
	Faker *Faker
}

Food is a faker struct for Food

func (Food) Fruit

func (f Food) Fruit() string

Fruit returns a fake fruit for Food

func (Food) Vegetable

func (f Food) Vegetable() string

Vegetable returns a fake fruit for Food

type Gamer

type Gamer struct {
	Faker *Faker
}

Gamer is a faker struct for Gamer

func (Gamer) Tag

func (g Gamer) Tag() string

Tag returns a fake gamer tag for Gamer

type Gender

type Gender struct {
	Faker *Faker
}

Gender is a faker struct for Gender

func (Gender) Abbr

func (f Gender) Abbr() string

Abbr returns a Gender name for Gender

func (Gender) Name

func (f Gender) Name() string

Name returns a Gender name for Gender

type GeneratorInterface

type GeneratorInterface interface {
	Intn(n int) int
	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) Name

func (f Genre) Name() string

Name returns a genre name for Genre

func (Genre) NameWithDescription

func (f Genre) NameWithDescription() (string, string)

NameWithDescription returns a name and description for Genre

type HTTPClient

type HTTPClient interface {
	Get(url string) (resp *http.Response, err error)
}

HTTPClient does HTTP requests to remote servers

type HTTPClientImpl

type HTTPClientImpl struct{}

HTTPClientImpl is the default implementation of HTTPClient

func (HTTPClientImpl) Get

func (HTTPClientImpl) Get(url string) (resp *http.Response, err error)

Get do a GET request and returns a *http.Response

type Hash

type Hash struct {
	Faker *Faker
}

Hash is the faker struct for Hashing Functions

func (Hash) MD5

func (hash Hash) MD5() string

MD5 returns a random MD5 based random hashed string

func (Hash) SHA256

func (hash Hash) SHA256() string

SHA256 returns a random sha256 based random hashed string

func (Hash) SHA512

func (hash Hash) SHA512() string

SHA512 returns a random sha512 based random hashed string

type Image

type Image struct {
	TempFileCreator TempFileCreator
	PngEncoder      PngEncoder
	// contains filtered or unexported fields
}

Image is a faker struct for Image

func (Image) Image

func (i Image) Image(width, height int) *os.File

Image returns a fake image file

type Internet

type Internet struct {
	Faker *Faker
}

Internet is a faker struct for Internet

func (Internet) CompanyEmail

func (i Internet) CompanyEmail() string

CompanyEmail returns a fake company email address for Internet

func (Internet) Domain

func (i Internet) Domain() string

Domain returns a fake domain for Internet

func (Internet) Email

func (i Internet) Email() string

Email returns a fake email address for Internet

func (Internet) FreeEmail

func (i Internet) FreeEmail() string

FreeEmail returns a fake free email address for Internet

func (Internet) FreeEmailDomain

func (i Internet) FreeEmailDomain() string

FreeEmailDomain returns a fake free email domain for Internet

func (Internet) HTTPMethod

func (i Internet) HTTPMethod() string

HTTPMethod returns a fake http method for Internet

func (Internet) Ipv4

func (i Internet) Ipv4() string

Ipv4 returns a fake ipv4 for Internet

func (Internet) Ipv6

func (i Internet) Ipv6() string

Ipv6 returns a fake ipv6 for Internet

func (Internet) LocalIpv4

func (i Internet) LocalIpv4() string

LocalIpv4 returns a fake local ipv4 for Internet

func (Internet) MacAddress

func (i Internet) MacAddress() string

MacAddress returns a fake mac address for Internet

func (Internet) Password

func (i Internet) Password() string

Password returns a fake password for Internet

func (Internet) Query

func (i Internet) Query() string

Query returns a fake query for Internet

func (Internet) SafeEmail

func (i Internet) SafeEmail() string

SafeEmail returns a fake safe email address for Internet

func (Internet) SafeEmailDomain

func (Internet) SafeEmailDomain() string

SafeEmailDomain returns a fake safe email domain for Internet

func (Internet) Slug

func (i Internet) Slug() string

Slug returns a fake slug for Internet

func (Internet) StatusCode

func (i Internet) StatusCode() int

StatusCode returns a fake status code for Internet

func (Internet) StatusCodeMessage

func (i Internet) StatusCodeMessage() string

StatusCodeMessage returns a fake status code message for Internet

func (Internet) StatusCodeWithMessage

func (i Internet) StatusCodeWithMessage() string

StatusCodeWithMessage returns a fake status code with message for Internet

func (Internet) TLD

func (i Internet) TLD() string

TLD returns a fake tld for Internet

func (Internet) URL

func (i Internet) URL() string

URL returns a fake url for Internet

func (Internet) User

func (i Internet) User() string

User returns a fake user for Internet

type Json

type Json struct {
	Faker *Faker
}

Json is a faker struct for json files

func (*Json) Object

func (j *Json) Object() map[string]interface{}

Object generates a random json object

func (*Json) String

func (j *Json) String() string

String generates a random json string

type Language

type Language struct {
	Faker *Faker
}

Language is a faker struct for Language

func (Language) Language

func (l Language) Language() string

Language returns a fake language name for Language

func (Language) LanguageAbbr

func (l Language) LanguageAbbr() string

LanguageAbbr returns a fake language name for Language

func (Language) ProgrammingLanguage

func (l Language) ProgrammingLanguage() string

ProgrammingLanguage returns a fake programming language for Language

type Lorem

type Lorem struct {
	Faker *Faker
}

Lorem is a faker struct for Lorem

func (Lorem) Bytes

func (l Lorem) Bytes(maxNbChars int) (out []byte)

Bytes returns fake bytes for Lorem

func (Lorem) Paragraph

func (l Lorem) Paragraph(nbSentences int) string

Paragraph returns a fake paragraph for Lorem

func (Lorem) Paragraphs

func (l Lorem) Paragraphs(nbParagraph int) []string

Paragraphs returns fake paragraphs for Lorem

func (Lorem) Sentence

func (l Lorem) Sentence(nbWords int) string

Sentence returns a fake sentence for Lorem

func (Lorem) Sentences

func (l Lorem) Sentences(nbSentences int) []string

Sentences returns fake sentences for Lorem

func (Lorem) Text

func (Lorem) Text(maxNbChars int) (out string)

Text returns a fake text for Lorem

func (Lorem) Word

func (l Lorem) Word() string

Word returns a fake word for Lorem

func (Lorem) Words

func (l Lorem) Words(nbWords int) []string

Words returns fake words for Lorem

type LoremFlickr

type LoremFlickr struct {
	HTTPClient      HTTPClient
	TempFileCreator TempFileCreator
	// contains filtered or unexported fields
}

LoremFlickr is a faker struct for LoremFlickr

func (LoremFlickr) Image

func (lf LoremFlickr) Image(width, height int, categories []string, prefix string, categoriesStrict bool) *os.File

Image generates a *os.File with a random image using the loremflickr.com service

type MimeType

type MimeType struct {
	Faker *Faker
}

MimeType is a faker struct for MimeType

func (MimeType) MimeType

func (p MimeType) MimeType() string

MimeType returns a fake mime type

type Music

type Music struct {
	Faker *Faker
}

Music is a faker struct for Music

func (Music) Author

func (Music) Author() string

Author returns the authors name for Music

func (Music) Genre

func (f Music) Genre() string

Genre returns genre for Music

func (Music) Length

func (f Music) Length() time.Duration

Length returns how long the song takes for Music

func (Music) Name

func (f Music) Name() string

Name returns a music name 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

func (p Payment) CreditCardExpirationDateString() string

CreditCardExpirationDateString returns a fake credit card expiration date in string format (i.e. mm/yy) for Payment

func (Payment) CreditCardNumber

func (p Payment) CreditCardNumber() string

CreditCardNumber returns a fake credit card number for Payment

func (Payment) CreditCardType

func (p Payment) CreditCardType() string

CreditCardType returns a fake credit card type for Payment

func (Payment) Iban added in v2.3.0

func (p Payment) Iban() string

Iban returns a fake IBAN 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) FirstName

func (p Person) FirstName() string

FirstName returns a fake first name for Person

func (Person) FirstNameFemale

func (p Person) FirstNameFemale() string

FirstNameFemale returns a fake female first name for Person

func (Person) FirstNameMale

func (p Person) FirstNameMale() string

FirstNameMale returns a fake male first mame for Person

func (Person) Gender

func (p Person) Gender() string

Gender returns a fake Gender for Person

func (Person) GenderFemale

func (Person) GenderFemale() string

GenderFemale returns a fake GenderFemale for Person

func (Person) GenderMale

func (Person) GenderMale() string

GenderMale returns a fake GenderMale for Person

func (Person) Image

func (p Person) Image() *os.File

Image return the person profile image

func (Person) LastName

func (p Person) LastName() string

LastName returns a fake last name for Person

func (Person) Name

func (p Person) Name() string

Name returns a fake name for Person

func (Person) NameAndGender

func (p Person) NameAndGender() (string, string)

NameAndGender returns a fake NameAndGender for Person

func (Person) NameFemale

func (p Person) NameFemale() string

NameFemale returns a fake NameFemale for Person

func (Person) NameMale

func (p Person) NameMale() string

NameMale returns a fake NameMale for Person

func (Person) SSN

func (p Person) SSN() string

SSN will generate a random Social Security Number

func (Person) Suffix

func (p Person) Suffix() string

Suffix returns a fake suffix for Person

func (Person) Title

func (p Person) Title() string

Title returns a fake title for Person

func (Person) TitleFemale

func (Person) TitleFemale() string

TitleFemale returns a fake female title for Person

func (Person) TitleMale

func (Person) TitleMale() string

TitleMale returns a fake male title for Person

type Pet

type Pet struct {
	Faker *Faker
}

Pet is a faker struct for Pet

func (Pet) Cat

func (p Pet) Cat() string

Cat returns a fake cat name for App

func (Pet) Dog

func (p Pet) Dog() string

Dog returns a fake dog name for App

func (Pet) Name

func (p Pet) Name() string

Name returns a fake pet name for App

type Phone

type Phone struct {
	Faker *Faker
}

Phone is a faker struct for Phone

func (Phone) AreaCode

func (p Phone) AreaCode() (code string)

AreaCode returns a fake area code for Phone

func (Phone) E164Number

func (p Phone) E164Number() string

E164Number returns a fake E164 phone number for Phone

func (Phone) ExchangeCode

func (p Phone) ExchangeCode() (code string)

ExchangeCode returns a fake exchange code for Phone

func (Phone) Number

func (p Phone) Number() string

Number returns a fake phone number for Phone

func (Phone) TollFreeAreaCode

func (p Phone) TollFreeAreaCode() string

TollFreeAreaCode returns a fake toll free area code for Phone

func (Phone) ToolFreeNumber

func (p Phone) ToolFreeNumber() string

ToolFreeNumber returns a fake tool free number for Phone

type PngEncoder

type PngEncoder interface {
	Encode(w io.Writer, m image.Image) error
}

PngEncoder encodes a image.Image to a io.Writer

type PngEncoderImpl

type PngEncoderImpl struct{}

PngEncoderImpl is the default implementation of the PngEncoder

func (PngEncoderImpl) Encode

func (PngEncoderImpl) Encode(w io.Writer, m image.Image) error

Encode does the encoding of the image.Image to an io.Writer

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 thispersondoesnotexist.com service

type Struct

type Struct struct {
	Faker *Faker
}

Struct is a faker struct for Struct

func (Struct) Fill

func (s Struct) Fill(v interface{})

Fill elements of a struct with random data

type TempFileCreator

type TempFileCreator interface {
	TempFile(prefix string) (f *os.File, err error)
}

TempFileCreator creates temporary files

type TempFileCreatorImpl

type TempFileCreatorImpl struct{}

TempFileCreatorImpl is the default implementation of TempFileCreator

func (TempFileCreatorImpl) TempFile

func (TempFileCreatorImpl) TempFile(prefix string) (f *os.File, err error)

TempFile creates a temporary file

type Time

type Time struct {
	Faker *Faker
}

Time is a faker struct for Time

func (Time) ANSIC

func (t Time) ANSIC(max time.Time) string

ANSIC returns a fake time in ANSIC format for Time

func (Time) AmPm

func (t Time) AmPm() string

AmPm returns a fake "am" or "pm" string for Time

func (Time) Century

func (t Time) Century() string

Century returns a fake century for Time

func (Time) DayOfMonth

func (t Time) DayOfMonth() int

DayOfMonth returns a fake day of month for Time

func (Time) DayOfWeek

func (t Time) DayOfWeek() time.Weekday

DayOfWeek returns a fake day of week for Time

func (Time) ISO8601

func (t Time) ISO8601(max time.Time) string

ISO8601 returns a fake time in ISO8601 format for Time

func (Time) Kitchen

func (t Time) Kitchen(max time.Time) string

Kitchen returns a fake time in Kitchen format for Time

func (Time) Month

func (t Time) Month() time.Month

Month returns a fake month for Time

func (Time) MonthName

func (t Time) MonthName() string

MonthName returns a fake month name for Time

func (Time) RFC1123

func (t Time) RFC1123(max time.Time) string

RFC1123 returns a fake time in RFC1123 format for Time

func (Time) RFC1123Z

func (t Time) RFC1123Z(max time.Time) string

RFC1123Z returns a fake time in RFC1123Z format for Time

func (Time) RFC3339

func (t Time) RFC3339(max time.Time) string

RFC3339 returns a fake time in RFC3339 format for Time

func (Time) RFC3339Nano

func (t Time) RFC3339Nano(max time.Time) string

RFC3339Nano returns a fake time in RFC3339Nano format for Time

func (Time) RFC822

func (t Time) RFC822(max time.Time) string

RFC822 returns a fake time in RFC822 format for Time

func (Time) RFC822Z

func (t Time) RFC822Z(max time.Time) string

RFC822Z returns a fake time in RFC822Z format for Time

func (Time) RFC850

func (t Time) RFC850(max time.Time) string

RFC850 returns a fake time in RFC850 format for Time

func (Time) RubyDate

func (t Time) RubyDate(max time.Time) string

RubyDate returns a fake date in ruby format for Time

func (Time) Time

func (t Time) Time(max time.Time) time.Time

Time returns a fake time for Time

func (Time) TimeBetween

func (t Time) TimeBetween(min, max time.Time) time.Time

TimeBetween returns a fake time between for Time

func (Time) Timezone

func (t Time) Timezone() string

Timezone returns a fake timezone for Time

func (Time) Unix

func (t Time) Unix(max time.Time) int64

Unix returns a fake unix for Time

func (Time) UnixDate

func (t Time) UnixDate(max time.Time) string

UnixDate returns a fake date in unix format for Time

func (Time) Year

func (t Time) Year() int

Year returns a fake year for Time

type UUID

type UUID struct {
	Faker *Faker
}

UUID is a faker struct for UUID

func (UUID) V4

func (UUID) V4() (uuid string)

V4 returns a fake UUID version 4

type UserAgent

type UserAgent struct {
	Faker *Faker
}

UserAgent is a faker struct for UserAgent

func (UserAgent) Chrome

func (u UserAgent) Chrome() string

Chrome returns a fake chrome browser user agent for Internet

func (UserAgent) Firefox

func (u UserAgent) Firefox() string

Firefox returns a fake firefox browser user agent for Internet

func (UserAgent) InternetExplorer

func (u UserAgent) InternetExplorer() string

InternetExplorer returns a fake internet explorer UserAgent

func (UserAgent) Opera

func (u UserAgent) Opera() string

Opera returns a fake opera browser user agent for Internet

func (UserAgent) Safari

func (u UserAgent) Safari() string

Safari returns a fake safari browser user agent for Internet

func (UserAgent) UserAgent

func (u UserAgent) UserAgent() string

UserAgent returns a fake browser user agent for Internet

type YouTube

type YouTube struct {
	Faker *Faker
}

YouTube is a faker struct for YouTube

func (YouTube) GenerateEmbededURL

func (y YouTube) GenerateEmbededURL() string

GenerateEmbededURL returns a fake embedded youtube video url

func (YouTube) GenerateFullURL

func (y YouTube) GenerateFullURL() string

GenerateFullURL returns a fake standard youtube video url

func (YouTube) GenerateShareURL

func (y YouTube) GenerateShareURL() string

GenerateShareURL returns a fake share youtube video url

func (YouTube) GenerateVideoID

func (YouTube) GenerateVideoID() (videoID string)

GenerateVideoID returns a youtube video id

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL