faker

package module
v1.19.1 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2023 License: MIT Imports: 24 Imported by: 85

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

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"

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"

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

Do your changes, add tests, run the tests.

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

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

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

This section is empty.

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 added in v1.3.0

func (a Address) CountryAbbr() string

CountryAbbr returns a fake country abbreviation for Address

func (Address) CountryCode added in v1.16.0

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 added in v1.3.0

type App struct {
	Faker *Faker
}

App is a faker struct for App

func (App) Name added in v1.3.0

func (a App) Name() string

Name returns a fake app name for App

func (App) Version added in v1.3.0

func (a App) Version() string

Version returns a fake app version for App

type Beer added in v1.3.0

type Beer struct {
	Faker *Faker
}

Beer is a faker struct for Beer

func (Beer) Alcohol added in v1.3.0

func (b Beer) Alcohol() string

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

func (Beer) Blg added in v1.3.0

func (b Beer) Blg() string

Blg will return a random beer blg between 5.0 and 20.0

func (Beer) Hop added in v1.3.0

func (b Beer) Hop() string

Hop will return a random beer hop

func (Beer) Ibu added in v1.3.0

func (b Beer) Ibu() string

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

func (Beer) Malt added in v1.3.0

func (b Beer) Malt() string

Malt will return a random beer malt

func (Beer) Name added in v1.3.0

func (b Beer) Name() string

Name will return a random beer name

func (Beer) Style added in v1.3.0

func (b Beer) Style() string

Style will return a random beer style

type BinaryString added in v1.6.0

type BinaryString struct {
	// contains filtered or unexported fields
}

BinaryString is the faker struct for BinaryString

func (BinaryString) BinaryString added in v1.6.0

func (bn BinaryString) BinaryString(length int) string

BinaryString returns a random binarystring of given input length

type Blood added in v1.13.0

type Blood struct {
	Faker *Faker
}

Blood is a faker struct for Blood

func (Blood) Name added in v1.13.0

func (f Blood) Name() string

Name returns a Blood name for Blood

type Boolean added in v1.3.0

type Boolean struct {
	Faker *Faker
}

Boolean is a faker struct for Boolean

func (Boolean) Bool added in v1.3.0

func (b Boolean) Bool() bool

Bool returns a fake bool for Faker

func (Boolean) BoolInt added in v1.3.0

func (b Boolean) BoolInt() int

BoolInt returns a fake bool for Integer Boolean

func (Boolean) BoolString added in v1.3.0

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

BoolString returns a fake bool for string Boolean

func (Boolean) BoolWithChance added in v1.3.0

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 added in v1.3.0

type Car struct {
	Faker *Faker
}

Car is a faker struct for Car

func (Car) Category added in v1.3.0

func (c Car) Category() string

Category will return a random car category

func (Car) FuelType added in v1.3.0

func (c Car) FuelType() string

FuelType will return a random car fuel type

func (Car) Maker added in v1.3.0

func (c Car) Maker() string

Maker will return a random car maker

func (Car) Model added in v1.3.0

func (c Car) Model() string

Model will return a random car model

func (Car) Plate added in v1.14.0

func (c Car) Plate() string

Plate will return a random car plate

func (Car) TransmissionGear added in v1.3.0

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 added in v1.11.0

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 added in v1.3.0

type ContactInfo struct {
	Phone string
	Email string
}

ContactInfo struct full of contact info

type Crypto added in v1.11.0

type Crypto struct {
	Faker *Faker
}

Crypto is a faker struct for generating bitcoin data

func (Crypto) Bech32Address added in v1.12.0

func (c Crypto) Bech32Address() string

Bech32Address generates a Bech32 bitcoin address

func (Crypto) Bech32AddressWithLength added in v1.12.0

func (c Crypto) Bech32AddressWithLength(length int) string

Bech32AddressWithLength generates a Bech32 bitcoin address with specified length.

func (Crypto) BitcoinAddress added in v1.12.0

func (c Crypto) BitcoinAddress() string

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

func (Crypto) EtheriumAddress added in v1.12.0

func (c Crypto) EtheriumAddress() string

EtheriumAddress returns a hexadecimal ethereum address of 42 characters.

func (Crypto) P2PKHAddress added in v1.12.0

func (c Crypto) P2PKHAddress() string

P2PKHAddress generates a P2PKH bitcoin address.

func (Crypto) P2PKHAddressWithLength added in v1.12.0

func (c Crypto) P2PKHAddressWithLength(length int) string

P2PKHAddressWithLength generates a P2PKH bitcoin address with specified length.

func (Crypto) P2SHAddress added in v1.12.0

func (c Crypto) P2SHAddress() string

P2SHAddress generates a P2SH bitcoin address.

func (Crypto) P2SHAddressWithLength added in v1.12.0

func (c Crypto) P2SHAddressWithLength(length int) string

P2SHAddressWithLength generates a P2PKH bitcoin address with specified length.

type Currency added in v1.9.0

type Currency struct {
	Faker *Faker
}

Currency is a faker struct for generating currency data

func (Currency) Code added in v1.9.0

func (c Currency) Code() string

Code returns a random currency code

func (Currency) Country added in v1.9.0

func (c Currency) Country() string

Country returns a random currency country

func (Currency) Currency added in v1.9.0

func (c Currency) Currency() string

Currency returns a random currency name

func (Currency) CurrencyAndCode added in v1.9.0

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

CurrencyAndCode returns a random currency name and currency code

func (Currency) Number added in v1.9.0

func (c Currency) Number() int

Number returns a random currency number

type Directory added in v1.15.0

type Directory struct {
	Faker      *Faker
	OSResolver OSResolver
}

Directory is a faker struct for Directory

func (Directory) Directory added in v1.15.0

func (d Directory) Directory(levels int) string

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

func (Directory) DriveLetter added in v1.15.0

func (d Directory) DriveLetter() string

DriveLetter returns a fake Win32 drive letter

func (Directory) UnixDirectory added in v1.15.0

func (d Directory) UnixDirectory(levels int) string

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

func (Directory) WindowsDirectory added in v1.15.0

func (d Directory) WindowsDirectory(levels int) string

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

type Emoji added in v1.3.0

type Emoji struct {
	Faker *Faker
}

Emoji is a faker struct for Emoji

func (Emoji) Emoji added in v1.3.0

func (a Emoji) Emoji() string

Emoji returns a fake emoji for Emoji

func (Emoji) EmojiCode added in v1.3.0

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 added in v1.3.0

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 added in v1.3.0

func (f Faker) Beer() Beer

Beer returns a fake Beer instance for Faker

func (Faker) BinaryString added in v1.6.0

func (f Faker) BinaryString() BinaryString

BinaryString returns a fake BinaryString instance for Faker

func (Faker) Blood added in v1.13.0

func (f Faker) Blood() Blood

Blood returns a fake Blood instance for Faker

func (Faker) Bool added in v1.0.2

func (f Faker) Bool() bool

Bool returns a fake bool for Faker

func (Faker) BoolWithChance added in v1.2.0

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 added in v1.3.0

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 added in v1.3.0

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 added in v1.11.0

func (f Faker) Crypto() Crypto

Crypto returns a fake Crypto instance for Faker

func (Faker) Currency added in v1.9.0

func (f Faker) Currency() Currency

Currency returns a fake Currency instance for Faker

func (Faker) Directory added in v1.15.0

func (f Faker) Directory() Directory

Directory returns a fake Directory instance for Faker

func (Faker) Emoji added in v1.3.0

func (f Faker) Emoji() Emoji

Emoji returns a fake Emoji instance for Faker

func (Faker) File added in v1.3.0

func (f Faker) File() File

File returns a fake File instance for Faker

func (Faker) Float added in v1.3.0

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

Float returns a fake random float number for Faker

func (Faker) Float32 added in v1.3.0

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

Float32 returns a fake random float64 number for Faker

func (Faker) Float64 added in v1.3.0

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

Float64 returns a fake random float64 number for Faker

func (Faker) Food added in v1.3.0

func (f Faker) Food() Food

Food returns a fake Food instance for Faker

func (Faker) Gamer added in v1.3.0

func (f Faker) Gamer() Gamer

Gamer returns a fake Gamer instance for Faker

func (Faker) Gender added in v1.5.0

func (f Faker) Gender() Gender

Gender returns a fake Gender instance for Faker

func (Faker) Genre added in v1.5.0

func (f Faker) Genre() Genre

Genre returns a fake Genre instance for Faker

func (Faker) Hash added in v1.8.0

func (f Faker) Hash() Hash

Hash returns a fake Hash instance for Faker

func (Faker) Image added in v1.0.3

func (f Faker) Image() Image

Image returns a fake Image instance for Faker

func (Faker) Int added in v1.0.3

func (f Faker) Int() int

Int returns a fake Int number for Faker

func (Faker) Int16 added in v1.3.0

func (f Faker) Int16() int16

Int16 returns a fake Int16 number for Faker

func (Faker) Int16Between added in v1.16.0

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 added in v1.0.3

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 added in v1.0.3

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 added in v1.3.0

func (f Faker) Int8() int8

Int8 returns a fake Int8 number for Faker

func (Faker) Int8Between added in v1.16.0

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 added in v1.19.0

func (f Faker) Json() Json

Json returns a fake Json instance for Faker

func (Faker) Language added in v1.3.0

func (f Faker) Language() Language

Language returns a fake Language instance for Faker

func (Faker) Letter added in v1.0.3

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 added in v1.4.0

func (f Faker) LoremFlickr() LoremFlickr

LoremFlickr returns a fake LoremFlickr instance for Faker

func (Faker) Map added in v1.3.0

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

Map returns a fake Map instance for Faker

func (Faker) MimeType added in v1.1.0

func (f Faker) MimeType() MimeType

MimeType returns a fake MimeType instance for Faker

func (Faker) Music added in v1.7.0

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 added in v1.3.0

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 added in v1.4.0

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 added in v1.0.1

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 added in v1.5.0

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 added in v1.5.0

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 added in v1.10.0

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 added in v1.3.0

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 added in v1.3.0

func (f Faker) UInt() uint

UInt returns a fake UInt number for Faker

func (Faker) UInt16 added in v1.3.0

func (f Faker) UInt16() uint16

UInt16 returns a fake UInt16 number for Faker

func (Faker) UInt16Between added in v1.16.0

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 added in v1.3.0

func (f Faker) UInt32() uint32

UInt32 returns a fake UInt32 number for Faker

func (Faker) UInt32Between added in v1.16.0

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 added in v1.3.0

func (f Faker) UInt64() uint64

UInt64 returns a fake UInt64 number for Faker

func (Faker) UInt64Between added in v1.16.0

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 added in v1.3.0

func (f Faker) UInt8() uint8

UInt8 returns a fake UInt8 number for Faker

func (Faker) UInt8Between added in v1.16.0

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 added in v1.16.0

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 added in v1.0.0

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 added in v1.1.0

func (f Faker) YouTube() YouTube

YouTube returns a fake YouTube instance for Faker

type File added in v1.3.0

type File struct {
	Faker      *Faker
	OSResolver OSResolver
}

File is a faker struct for File

func (File) AbsoluteFilePath added in v1.15.0

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 added in v1.15.0

func (f File) AbsoluteFilePathForUnix(levels int) string

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

func (File) AbsoluteFilePathForWindows added in v1.15.0

func (f File) AbsoluteFilePathForWindows(levels int) string

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

func (File) Extension added in v1.3.0

func (f File) Extension() string

Extension returns a fake Extension file

func (File) FilenameWithExtension added in v1.3.0

func (f File) FilenameWithExtension() string

FilenameWithExtension returns a fake file name with extension

type Food added in v1.3.0

type Food struct {
	Faker *Faker
}

Food is a faker struct for Food

func (Food) Fruit added in v1.3.0

func (f Food) Fruit() string

Fruit returns a fake fruit for Food

func (Food) Vegetable added in v1.3.0

func (f Food) Vegetable() string

Vegetable returns a fake fruit for Food

type Gamer added in v1.3.0

type Gamer struct {
	Faker *Faker
}

Gamer is a faker struct for Gamer

func (Gamer) Tag added in v1.3.0

func (g Gamer) Tag() string

Tag returns a fake gamer tag for Gamer

type Gender added in v1.5.0

type Gender struct {
	Faker *Faker
}

Gender is a faker struct for Gender

func (Gender) Abbr added in v1.5.0

func (f Gender) Abbr() string

Abbr returns a Gender name for Gender

func (Gender) Name added in v1.5.0

func (f Gender) Name() string

Name returns a Gender name for Gender

type GeneratorInterface added in v1.12.0

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 added in v1.5.0

type Genre struct {
	Faker *Faker
}

Genre is a faker struct for Genre

func (Genre) Name added in v1.5.0

func (f Genre) Name() string

Name returns a genre name for Genre

func (Genre) NameWithDescription added in v1.5.0

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

NameWithDescription returns a name and description for Genre

type HTTPClient added in v1.11.0

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

HTTPClient does HTTP requests to remote servers

type HTTPClientImpl added in v1.11.0

type HTTPClientImpl struct{}

HTTPClientImpl is the default implementation of HTTPClient

func (HTTPClientImpl) Get added in v1.11.0

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

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

type Hash added in v1.8.0

type Hash struct {
	Faker *Faker
}

Hash is the faker struct for Hashing Functions

func (Hash) MD5 added in v1.8.0

func (hash Hash) MD5() string

MD5 returns a random MD5 based random hashed string

func (Hash) SHA256 added in v1.8.0

func (hash Hash) SHA256() string

SHA256 returns a random sha256 based random hashed string

func (Hash) SHA512 added in v1.8.0

func (hash Hash) SHA512() string

SHA512 returns a random sha512 based random hashed string

type Image added in v1.0.3

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

Image is a faker struct for Image

func (Image) Image added in v1.0.3

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 added in v1.0.2

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 added in v1.0.2

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 added in v1.3.0

func (i Internet) StatusCode() int

StatusCode returns a fake status code for Internet

func (Internet) StatusCodeMessage added in v1.3.0

func (i Internet) StatusCodeMessage() string

StatusCodeMessage returns a fake status code message for Internet

func (Internet) StatusCodeWithMessage added in v1.3.0

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 added in v1.19.0

type Json struct {
	Faker *Faker
}

Json is a faker struct for json files

func (*Json) Object added in v1.19.0

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

Object generates a random json object

func (*Json) String added in v1.19.0

func (j *Json) String() string

String generates a random json string

type Language added in v1.3.0

type Language struct {
	Faker *Faker
}

Language is a faker struct for Language

func (Language) Language added in v1.3.0

func (l Language) Language() string

Language returns a fake language name for Language

func (Language) LanguageAbbr added in v1.3.0

func (l Language) LanguageAbbr() string

LanguageAbbr returns a fake language name for Language

func (Language) ProgrammingLanguage added in v1.3.0

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 added in v1.0.2

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 added in v1.4.0

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

LoremFlickr is a faker struct for LoremFlickr

func (LoremFlickr) Image added in v1.4.0

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 added in v1.1.0

type MimeType struct {
	Faker *Faker
}

MimeType is a faker struct for MimeType

func (MimeType) MimeType added in v1.1.0

func (p MimeType) MimeType() string

MimeType returns a fake mime type

type Music added in v1.7.0

type Music struct {
	Faker *Faker
}

Music is a faker struct for Music

func (Music) Author added in v1.7.0

func (Music) Author() string

Author returns the authors name for Music

func (Music) Genre added in v1.7.0

func (f Music) Genre() string

Genre returns genre for Music

func (Music) Length added in v1.7.0

func (f Music) Length() time.Duration

Length returns how long the song takes for Music

func (Music) Name added in v1.7.0

func (f Music) Name() string

Name returns a music name for Music

type OSResolver added in v1.15.0

type OSResolver interface {
	OS() string
}

OSResolver returns the GOOS value for operating an operating system

type OSResolverImpl added in v1.15.0

type OSResolverImpl struct{}

OSResolverImpl is the default implementation of OSResolver

func (OSResolverImpl) OS added in v1.15.0

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

type Person

type Person struct {
	Faker *Faker
}

Person is a faker struct for Person

func (Person) Contact added in v1.3.0

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 added in v1.3.0

func (p Person) Gender() string

Gender returns a fake Gender for Person

func (Person) GenderFemale added in v1.3.0

func (Person) GenderFemale() string

GenderFemale returns a fake GenderFemale for Person

func (Person) GenderMale added in v1.3.0

func (Person) GenderMale() string

GenderMale returns a fake GenderMale for Person

func (Person) Image added in v1.4.0

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 added in v1.3.0

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

NameAndGender returns a fake NameAndGender for Person

func (Person) NameFemale added in v1.3.0

func (p Person) NameFemale() string

NameFemale returns a fake NameFemale for Person

func (Person) NameMale added in v1.3.0

func (p Person) NameMale() string

NameMale returns a fake NameMale for Person

func (Person) SSN added in v1.3.0

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 added in v1.3.0

type Pet struct {
	Faker *Faker
}

Pet is a faker struct for Pet

func (Pet) Cat added in v1.3.0

func (p Pet) Cat() string

Cat returns a fake cat name for App

func (Pet) Dog added in v1.3.0

func (p Pet) Dog() string

Dog returns a fake dog name for App

func (Pet) Name added in v1.3.0

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 added in v1.11.0

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

PngEncoder encodes a image.Image to a io.Writer

type PngEncoderImpl added in v1.11.0

type PngEncoderImpl struct{}

PngEncoderImpl is the default implementation of the PngEncoder

func (PngEncoderImpl) Encode added in v1.11.0

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

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

type ProfileImage added in v1.4.0

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

ProfileImage is a faker struct for ProfileImage

func (ProfileImage) Image added in v1.4.0

func (pi ProfileImage) Image() *os.File

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

type Struct added in v1.3.0

type Struct struct {
	Faker *Faker
}

Struct is a faker struct for Struct

func (Struct) Fill added in v1.3.0

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

Fill elements of a struct with random data

type TempFileCreator added in v1.11.0

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

TempFileCreator creates temporary files

type TempFileCreatorImpl added in v1.11.0

type TempFileCreatorImpl struct{}

TempFileCreatorImpl is the default implementation of TempFileCreator

func (TempFileCreatorImpl) TempFile added in v1.11.0

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 added in v1.0.0

type UUID struct {
	Faker *Faker
}

UUID is a faker struct for UUID

func (UUID) V4 added in v1.0.0

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 added in v1.1.0

type YouTube struct {
	Faker *Faker
}

YouTube is a faker struct for YouTube

func (YouTube) GenerateEmbededURL added in v1.1.0

func (y YouTube) GenerateEmbededURL() string

GenerateEmbededURL returns a fake embedded youtube video url

func (YouTube) GenerateFullURL added in v1.1.0

func (y YouTube) GenerateFullURL() string

GenerateFullURL returns a fake standard youtube video url

func (YouTube) GenerateShareURL added in v1.1.0

func (y YouTube) GenerateShareURL() string

GenerateShareURL returns a fake share youtube video url

func (YouTube) GenerateVideoID added in v1.1.0

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