faker

package module
v1.7.3 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2022 License: MIT Imports: 14 Imported by: 8

README

Faker

Go Go Report Card codecov awesome-go GoReference

Random fake data and struct generator for Go.

  • More than 100 generator functions
  • Struct generator
  • Unique data generator
  • Builtin types support
  • Easily customizable
  • Zero dependencies
  • Recursive infinite loop detector
  • Benchmarks (coming soon)

Installation

go get github.com/pioz/faker

Example

faker.SetSeed(623)

fmt.Println(faker.Username())
fmt.Println(faker.String())
fmt.Println(faker.IntInRange(1, 10))
fmt.Println(faker.CurrencyName())
// Output: spicule
// gzaazJyRGt3jDnVh6ik7R9FO0AU1HcOzdOXbmNVBRQ5pq8n9tHf9B21PIFozLEzsoY4wILvZjTxSLQmD3UOAamDgVR411T3YHleDTgLuz90XSO3NFZm1AnaJiJamVRcNGD2zmi4qWkcjKF3E4JKgn1DiCeC3eSb5WELsw8XqRzlvJqG
// 10
// Myanmar Kyat

Please refer to the godoc for all available functions and more.

Struct Builder Example

faker.SetSeed(622)

// Define a new builder
colorBuilder := func(params ...string) (interface{}, error) {
  return faker.Pick("Red", "Yellow", "Blue", "Black", "White"), nil
}

// Register a new builder named "color" for string type
err := faker.RegisterBuilder("color", "string", colorBuilder)
if err != nil {
  panic(err)
}

type Animal struct {
  Name  string `faker:"username"`
  Color string `faker:"color"` // Use custom color builder
}

type Person struct {
  FirstName string            `faker:"firstName"`         // Any available function case insensitive
  LastName  *string           `faker:"lastName"`          // Pointer are also supported
  Age       int               `faker:"intinrange(0,120)"` // Can call with parameters
  UUID      string            `faker:"uuid;unique"`       // Guarantees a unique value
  Number    int               `faker:"-"`                 // Skip this field
  Code      string            // No tag to use default builder for this field type
  Pet       Animal            // Recursively fill this struct
  Nicknames []string          `faker:"username;len=3"`          // Build an array of size 3 using faker.Username function
  Extra     map[string]string `faker:"stringWithSize(3);len=2"` // map are supported
}

p := Person{}
err = faker.Build(&p)
if err != nil {
  panic(err)
}
fmt.Println(p.FirstName)
fmt.Println(*p.LastName)
fmt.Println(p.Age)
fmt.Println(p.UUID)
fmt.Println(p.Number)
fmt.Println(p.Code)
fmt.Println(p.Pet.Name)
fmt.Println(p.Pet.Color)
fmt.Println(len(p.Nicknames))
fmt.Println(p.Nicknames[0])
fmt.Println(p.Nicknames[1])
fmt.Println(p.Nicknames[2])
fmt.Println(p.Extra)
// Output: Wilber
// Gutkowski
// 25
// ff8d6917-b920-46e6-b1be-dc2d48becfcb
// 0
// z
// honegger
// Red
// 3
// teagan
// polypeptide
// chinfest
// map[70w:3F6 gQS:isq]

Factory

One of the nice things about Faker is that it can also be used as a factory library. In fact when we call the faker.Build function if a value is not zero then it is not modified, leaving the original value. This allows you to create factory functions very easily:

faker.SetSeed(623)

type User struct {
    Username string `faker:"username"`
    Email    string `faker:"email"`
    Country  string `faker:"CountryAlpha2"`
}

italianUserFactory := func() *User {
    u := &User{Country: "IT"}
    faker.Build(u)
    return u
}

italianUser := italianUserFactory()
fmt.Println(italianUser)
// Output: &{spicule hoag@ornamented.biz IT}

Customization

A builder is a variadic function that will take an arbitrary number of strings as arguments and return an interface or an error. This function (builder) can be used to generate fake data and customize the behaviour of Faker. Here an example:

faker.SetSeed(1802)

// Define a new builder
builder := func(params ...string) (interface{}, error) {
    if len(params) > 0 && params[0] == "melee" {
        return faker.Pick("Barbarian", "Bard", "Fighter", "Monk", "Paladin", "Rogue"), nil
    }
    return faker.Pick("Cleric", "Druid", "Ranger", "Sorcerer", "Warlock", "Wizard"), nil
}

// Register a new builder named "dndClass" for string type
err := faker.RegisterBuilder("dndClass", "string", builder)
if err != nil {
    panic(err)
}

player := &struct {
    Class string `faker:"dndClass(melee)"`
    // other fields ...
}{}

// Build a struct with fake data
faker.Build(&player)

fmt.Println(player.Class)
// Output: Paladin

Contributing with new generator functions

If you want to contribute to faker with new generator functions please read this wiki!

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/pioz/faker/issues.

License

The package is available as open source under the terms of the MIT License.

Documentation

Overview

Package faker is a random data generator and struct fake data generator.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddressCity

func AddressCity() string

AddressCity will build a random city string.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(1300)
	fmt.Println(faker.AddressCity())
}
Output:

Ntoroko

func AddressFull

func AddressFull() string

AddressFull will build a random full address string.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(1307)
	fmt.Println(faker.AddressFull())
}
Output:

John Snow
Apt. 248
943 Wager Street
Berezniki PR 52209
Saudi Arabia

func AddressSecondaryAddress

func AddressSecondaryAddress() string

AddressSecondaryAddress will build a random secondary address string.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(1305)
	fmt.Println(faker.AddressSecondaryAddress())
}
Output:

Suite 208

func AddressState

func AddressState() string

AddressState will build a random USA state string.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(1301)
	fmt.Println(faker.AddressState())
}
Output:

Indiana

func AddressStateCode

func AddressStateCode() string

AddressStateCode will build a random USA state code string.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(1302)
	fmt.Println(faker.AddressStateCode())
}
Output:

DC

func AddressStreetName

func AddressStreetName() string

AddressStreetName will build a random street name string.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(1303)
	fmt.Println(faker.AddressStreetName())
}
Output:

Hopton Street

func AddressStreetNumber

func AddressStreetNumber() string

AddressStreetNumber will build a random street number string.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(1304)
	fmt.Println(faker.AddressStreetNumber())
}
Output:

81-680

func AddressZip

func AddressZip() string

AddressZip will build a random ZIP (postal code) string.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(1306)
	fmt.Println(faker.AddressZip())
}
Output:

36168

func Article

func Article() string

Article will build a random article.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(1604)
	fmt.Println(faker.Article())
}
Output:

Few can name a sincere chimpanzee that isn't a selective cranberry. They were lost without the straightforward camel that composed their puppy; However, the zebras could be said to resemble tidy bears. Cultured hippopotamus show us how blackberries can be squirrels. In recent years, a cherry sees a nectarine as a resolute bear. This is not to discredit the idea that a crocodile is an emotional prune;
An amiable watermelon is a horse of the mind. To be more specific, a panda can hardly be considered an inventive hamster without also being a lime? A camel of the kangaroo is assumed to be a cooperative tiger; Before plums, kangaroos were only melons.
In modern times those puppies are nothing more than persimmons. The literature would have us believe that a silly octopus is not but a rabbit. Their blackberry was, in this moment, a protective banana. A puppy is the pear of a grapes. Some posit the amiable pig to be less than helpful.
Far from the truth, authors often misinterpret the owl as a calm crocodile, when in actuality it feels more like a placid orange. Extending this logic, some honest turtles are thought of simply as horses. The cherry of an apple becomes a brave chimpanzee; Draped neatly on a hanger, authors often misinterpret the octopus as a happy cranberry, when in actuality it feels more like a harmonious kiwi. The oranges could be said to resemble unusual lemons! Their melon was, in this moment, an impartial hippopotamus. Plums are diligent frogs. By the waya zebra is a thrifty fish.
The giraffes could be said to resemble broad-minded kangaroos. The first jolly plum is, in its own way, a grape! Extending this logic, the lobster is an orange. Shouting with happiness, the affable grape comes from a thrifty kiwi. However, their panda was, in this moment, an upbeat spider. An inventive deer's kumquat comes with it the thought that the excited cranberry is a spider.
Those bears are nothing more than goldfishes. Authors often misinterpret the bird as an imaginative persimmon, when in actuality it feels more like an intellectual apricot! An apple is an owl from the right perspective. A camel is the fig of an octopus. What we don't know for sure is whether or not foxes are faithful lions. The literature would have us believe that a pleasant tiger is not but a shark.

func ArticleWithParagraphCount

func ArticleWithParagraphCount(n int) string

ArticleWithParagraphCount will build a random article string consisting of n paragraphs.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(1603)
	fmt.Println(faker.ArticleWithParagraphCount(5))
}
Output:

The fly of a pig becomes an alert blueberry. The vivacious apricot reveals itself as a powerful lime to those who look! Few can name a resolute turtle that isn't a happy kiwi; The pandas could be said to resemble fair-minded goats. Few can name a modest wolf that isn't a sensible fly! Some generous alligators are thought of simply as chimpanzees. Few can name a thrifty pineapple that isn't a pleasant apricot.
By the waybefore chickens, snakes were only lemons. If this was somewhat unclear, a kitten is a cow from the right perspective? Shouting with happiness, rabbits are romantic fishes. A watermelon is a humorous apricot. The willing deer comes from a diplomatic turtle? We can assume that any instance of a strawberry can be construed as an affable fish. Framed in a different way, the dolphins could be said to resemble receptive cherries. An intuitive fly's seal comes with it the thought that the relieved cranberry is a sheep. A blackberry is a panda's cheetah.
A turtle sees a panda as an efficient octopus. Seals are compassionate figs; Shouting with happiness, one cannot separate cherries from talented monkeys! Some skillful giraffes are thought of simply as elephants! Few can name an impartial cranberry that isn't a painstaking grapes. A cheetah can hardly be considered a resolute shark without also being a kitten. We know that they were lost without the helpful cherry that composed their giraffe. An energetic goldfish's grapes comes with it the thought that the eminent lemon is a blueberry! As far as he is concerned, their kumquat was, in this moment, a happy eagle. A careful grape's plum comes with it the thought that the industrious turtle is a duck.
Their strawberry was, in this moment, a delightful seal. A lively lion is a monkey of the mind. An ant of the plum is assumed to be a kind-hearted frog. It's an undeniable fact, really; they were lost without the brave fish that composed their snail. A mature tiger's zebra comes with it the thought that the resourceful rat is a sheep.
In modern times a hamster sees a peach as a helpful fig. In modern times a dog is the fox of a bee. One cannot separate chimpanzees from diplomatic snakes. Some funny seals are thought of simply as grapes; Having been a gymnast, they were lost without the encouraging nectarine that composed their pineapple. This is not to discredit the idea that punctual lions show us how zebras can be pears. Skillful chickens show us how chimpanzees can be lobsters! Few can name an inventive turtle that isn't an adaptable raspberry. Washing and polishing the car,we can assume that any instance of a lime can be construed as an intellectual currant. A cat can hardly be considered a peaceful scorpion without also being a crocodile;

func BinaryGender

func BinaryGender() string

BinaryGender will build a random binary gender string (Male or Female).

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(1501)
	fmt.Println(faker.BinaryGender())
}
Output:

Male

func Bool

func Bool() bool

Bool will build a random boolean value (true or false).

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(102)
	fmt.Println(faker.Bool())
	fmt.Println(faker.Bool())
}
Output:

true
false

func Build

func Build(input interface{}) error

Build fills in exported elements of a struct with random data based on the value of `faker` tag of exported elements. The faker tag value can be any available function (case insensitive).

Use `faker:"-"` to explicitly skip an element.

Use `faker:"skip if FieldName"` to explicitly skip this field if another field (FieldName) is not empty.

Use `faker:"unique"` to guarantee a unique value.

Use `faker:"len=x"` to specify the length of a slice or the size of a map (if ommitted, will be generated a slice or map with random size between 1 and 8).

Built-in supported types are: bool, int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64, float32, float64, string. Other standard library supported types are time.Time and time.Duration. But is really easy to extend faker to add other builders to support other types and or customize faker's behavior (see RegisterBuilder function).

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(621)
	type Person struct {
		Name   string `faker:"firstName"`
		City   string `faker:"addressCity"`
		Age    int    `faker:"intinrange(0,120)"`
		Code   string
		UUID   string `faker:"uuid;unique"`
		Number int
	}

	p := Person{}
	err := faker.Build(&p)
	if err != nil {
		panic(err)
	}
	fmt.Println(p.Name)
	fmt.Println(p.City)
	fmt.Println(p.Age)
	fmt.Println(p.Code)
	fmt.Println(p.UUID)
	fmt.Println(p.Number)
}
Output:

Elizabeth
Thai Nguyen
7
QtCMxnMc
566235bc-4211-4ff2-b966-fa2d49d2b167
1267435813
Example (Array)
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(623)

	type User struct {
		Username string `faker:"username"`
		Email    string `faker:"email"`
		Country  string `faker:"CountryAlpha2"`
	}

	// Build 3 users
	users := make([]User, 3)
	err := faker.Build(&users)
	if err != nil {
		panic(err)
	}
	fmt.Printf("%+v", users)
}
Output:

[{Username:spicule Email:hoag@ornamented.biz Country:FI} {Username:twelvetone Email:mechanics@ramiform.name Country:TL} {Username:considerate Email:solnit@canonry.biz Country:TG}]
Example (ConditionalSkip)
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(623)

	type Author struct {
		Id   uint64 `faker:"uint64inrange(1,10)"`
		Name string `faker:"FirstName"`
	}

	type Post struct {
		Title    string  `faker:"Sentence"`
		AuthorId uint64  `faker:"-"`
		Author   *Author `faker:"skip if AuthorId"`
	}

	// Gen random Post with Author
	post1 := &Post{}
	err := faker.Build(&post1)
	if err != nil {
		panic(err)
	}

	// Gen random Post with same Author
	post2 := &Post{AuthorId: post1.Author.Id}
	err = faker.Build(&post2)
	if err != nil {
		panic(err)
	}

	fmt.Println(post1.Author.Id == post2.AuthorId)
	fmt.Println(post2.Author == nil)
}
Output:

true
true
Example (Factory)
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(623)

	type User struct {
		Username string `faker:"username"`
		Email    string `faker:"email"`
		Country  string `faker:"CountryAlpha2"`
	}

	italianUserFactory := func() *User {
		u := &User{Country: "IT"}
		err := faker.Build(u)
		if err != nil {
			panic(err)
		}
		return u
	}

	italianUser := italianUserFactory()
	fmt.Println(italianUser)
}
Output:

&{spicule hoag@ornamented.biz IT}
Example (Recursive)
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(622)

	// Define a new builder
	colorBuilder := func(params ...string) (interface{}, error) {
		return faker.Pick("Red", "Yellow", "Blue", "Black", "White"), nil
	}

	// Register a new builder named "color" for string type
	err := faker.RegisterBuilder("color", "string", colorBuilder)
	if err != nil {
		panic(err)
	}

	type Animal struct {
		Name  string `faker:"username"`
		Color string `faker:"color"` // Use custom color builder
	}

	type Person struct {
		FirstName string            `faker:"firstName"`         // Any available function case insensitive
		LastName  *string           `faker:"lastName"`          // Pointer are also supported
		Age       int               `faker:"intinrange(0,120)"` // Can call with parameters
		UUID      string            `faker:"uuid;unique"`       // Guarantees a unique value
		Number    int               `faker:"-"`                 // Skip this field
		Code      string            // No tag to use default builder for this field type
		Pet       Animal            // Recursively fill this struct
		Nicknames []string          `faker:"username;len=3"`          // Build an array of size 3 using faker.Username function
		Extra     map[string]string `faker:"stringWithSize(3);len=2"` // map are supported
	}

	p := Person{}
	err = faker.Build(&p)
	if err != nil {
		panic(err)
	}
	fmt.Println(p.FirstName)
	fmt.Println(*p.LastName)
	fmt.Println(p.Age)
	fmt.Println(p.UUID)
	fmt.Println(p.Number)
	fmt.Println(p.Code)
	fmt.Println(p.Pet.Name)
	fmt.Println(p.Pet.Color)
	fmt.Println(len(p.Nicknames))
	fmt.Println(p.Nicknames[0])
	fmt.Println(p.Nicknames[1])
	fmt.Println(p.Nicknames[2])
	fmt.Println(p.Extra)
}
Output:

Wilber
Gutkowski
25
ff8d6917-b920-46e6-b1be-dc2d48becfcb
0
zN
clung
Red
3
polypeptide
chinfest
chungchungking
map[0w3:F6Y QSi:sq7]

func ClearAllUniqCache

func ClearAllUniqCache()

ClearAllUniqCache delete all results for all groups of run.

func ClearUniqCache

func ClearUniqCache(group string)

ClearUniqCache delete all results for the group group.

func ColorHSL added in v1.7.1

func ColorHSL() [3]int

ColorHSL will build a random HSL color. First element is Hue, a degree on the color wheel from 0 to 360. 0 is red, 120 is green, 240 is blue. Second element is Saturation, a percentage value; 0 means a shade of gray and 100 is the full color. Third element is Lightness, also a percentage; 0 is black, 100 is white.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(1903)
	fmt.Println(faker.ColorHSL())
}
Output:

[135 5 41]

func ColorHex added in v1.7.1

func ColorHex() string

ColorHex will build a random hex color string. First element is the Red value from 0 to 255; second element is the Green value from 0 to 255; third element is the Blue value from 0 to 255.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(1902)
	fmt.Println(faker.ColorHex())
}
Output:

#1908b0

func ColorName added in v1.7.1

func ColorName() string

ColorName will build a random color name string.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(1900)
	fmt.Println(faker.ColorName())
}
Output:

apricot

func ColorRGB added in v1.7.1

func ColorRGB() [3]int

ColorRGB will build a random RGB color.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(1901)
	fmt.Println(faker.ColorRGB())
}
Output:

[137 240 27]

func CountryAlpha2

func CountryAlpha2() string

CountryAlpha2 will build a random 2 characters country code string.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(1001)
	fmt.Println(faker.CountryAlpha2())
}
Output:

ML

func CountryAlpha3

func CountryAlpha3() string

CountryAlpha3 will build a random 3 characters country code string.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(1002)
	fmt.Println(faker.CountryAlpha3())
}
Output:

TKM

func CountryFlag

func CountryFlag() string

CountryFlag will build a random emoji flag string.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(1003)
	fmt.Println(faker.CountryFlag())
}
Output:

🇳🇷

func CountryName

func CountryName() string

CountryName will build a random country name string.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(1000)
	fmt.Println(faker.CountryName())
}
Output:

Rwanda

func CountryNationality

func CountryNationality() string

CountryNationality will build a random nationality string.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(1002)
	fmt.Println(faker.CountryNationality())
}
Output:

Venezuelan

func CurrencyCode

func CurrencyCode() string

CurrencyCode will build a random currency code string.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(1201)
	fmt.Println(faker.CurrencyCode())
}
Output:

XOF

func CurrencyName

func CurrencyName() string

CurrencyName will build a random currency name string.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(1200)
	fmt.Println(faker.CurrencyName())
}
Output:

Sierra Leonean Leone

func CurrencySymbol

func CurrencySymbol() string

CurrencySymbol will build a random currency symbol string.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(1202)
	fmt.Println(faker.CurrencySymbol())
}
Output:

func Day

func Day() int

Day will build a random day between 1 - 31.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(49)
	fmt.Println(faker.Day())
}
Output:

5

func Digits

func Digits() string

Digits will build a random string of only digits of length between 1 and 8.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(903)
	fmt.Println(faker.Digits())
}
Output:

615512

func DigitsWithSize

func DigitsWithSize(size int) string

DigitsWithSize will build a random string of only digits of length size.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(902)
	fmt.Println(faker.DigitsWithSize(6))
}
Output:

083232

func Domain

func Domain() string

Domain will build a random domain string.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(1701)
	fmt.Println(faker.Domain())
}
Output:

lorusso.name

func Duration

func Duration() time.Duration

Duration will build a random time.Duration.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(42)
	fmt.Println(faker.Duration())
}
Output:

-1606331h18m2.623497133s

func DurationInRange

func DurationInRange(min, max time.Duration) time.Duration

DurationInRange will build a random time.Duration between min and max included.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(41)
	fmt.Println(faker.DurationInRange(100, 200))
}
Output:

158ns

func Email

func Email() string

Email will build a random email address string.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(1702)
	fmt.Println(faker.Email())
}
Output:

homocercal@fulmer.net

func FemaleFirstName

func FemaleFirstName() string

FemaleFirstName will build a random female first name string.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(1401)
	fmt.Println(faker.FemaleFirstName())
}
Output:

Sharell

func FirstName

func FirstName() string

FirstName will build a random first name string.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(1403)
	fmt.Println(faker.FirstName())
}
Output:

Barney

func Float32

func Float32() float32

Float32 will build a random float32.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(26)
	fmt.Println(faker.Float32())
}
Output:

1.5426473e+38

func Float32InRange

func Float32InRange(min, max float32) float32

Float32InRange will build a random float32 between min and max included.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(25)
	fmt.Println(faker.Float32InRange(10, 20))
	fmt.Println(faker.Float32InRange(-20, -10))
	fmt.Println(faker.Float32InRange(-20, -30))
}
Output:

18.961363
-15.832848
-20

func Float64

func Float64() float64

Float64 will build a random float64.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(24)
	fmt.Println(faker.Float64())
}
Output:

6.696671980874496e+307

func Float64InRange

func Float64InRange(min, max float64) float64

Float64InRange will build a random float64 between min and max included.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(23)
	fmt.Println(faker.Float64InRange(1, 2))
	fmt.Println(faker.Float64InRange(-2, -1))
	fmt.Println(faker.Float64InRange(-2, -3))
}
Output:

1.8120965248489755
-1.4513652135502495
-2

func FreeEmail

func FreeEmail() string

FreeEmail will build a random free email address string (gmail, hotmail, yahoo...).

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(1703)
	fmt.Println(faker.FreeEmail())
}
Output:

atlas@gmail.com

func FullName

func FullName() string

FullName will build a random full name string.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(1407)
	fmt.Println(faker.FullName())
}
Output:

Sawyer Littel

func Gender

func Gender() string

Gender will build a random gender string.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(1500)
	fmt.Println(faker.Gender())
}
Output:

Cisgender Male

func GetData

func GetData(namespace, group string) (interface{}, error)

GetData return a random value of the Pool present in the group group with namespace namespace or error if the pool does not exist. Faker organize fake data in a map of string and map of string and array of interface. The keys of the first level map are called namespaces, the keys of the second level map are called groups.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(801)
	faker.SetPool("address", "city", faker.Pool{"New York", "Rome"})
	value, err := faker.GetData("address", "city")
	if err != nil {
		panic(err)
	}
	fmt.Println(value)
}
Output:

New York

func Hour

func Hour() int

Hour will build a random hour in military time.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(48)
	fmt.Println(faker.Hour())
}
Output:

9

func Int

func Int() int

Int will build a random int.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(4)
	fmt.Println(faker.Int())
}
Output:

477987042

func Int16

func Int16() int16

Int16 will build a random int16.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(10)
	fmt.Println(faker.Int16())
}
Output:

-24938

func Int16InRange

func Int16InRange(min, max int16) int16

Int16InRange will build a random int16 between min and max included.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(9)
	fmt.Println(faker.Int16InRange(10, 20))
	fmt.Println(faker.Int16InRange(-20, -10))
	fmt.Println(faker.Int16InRange(-20, -30))
}
Output:

14
-16
-20

func Int32

func Int32() int32

Int32 will build a random int32.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(8)
	fmt.Println(faker.Int32())
}
Output:

-417194768

func Int32InRange

func Int32InRange(min, max int32) int32

Int32InRange will build a random int32 between min and max included.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(7)
	fmt.Println(faker.Int32InRange(10, 20))
	fmt.Println(faker.Int32InRange(-20, -10))
	fmt.Println(faker.Int32InRange(-20, -30))
}
Output:

15
-16
-20

func Int64

func Int64() int64

Int64 will build a random int64.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(6)
	fmt.Println(faker.Int64())
}
Output:

-5917743806733054187

func Int64InRange

func Int64InRange(min, max int64) int64

Int64InRange will build a random int64 between min and max included.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(5)
	fmt.Println(faker.Int64InRange(10, 20))
	fmt.Println(faker.Int64InRange(-20, -10))
	fmt.Println(faker.Int64InRange(-20, -30))
}
Output:

10
-19
-20

func Int8

func Int8() int8

Int8 will build a random int8.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(12)
	fmt.Println(faker.Int8())
}
Output:

-101

func Int8InRange

func Int8InRange(min, max int8) int8

Int8InRange will build a random int8 between min and max included.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(11)
	fmt.Println(faker.Int8InRange(10, 20))
	fmt.Println(faker.Int8InRange(-20, -10))
	fmt.Println(faker.Int8InRange(-20, -30))
}
Output:

15
-14
-20

func IntInRange

func IntInRange(min, max int) int

IntInRange will build a random int between min and max included.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(3)
	fmt.Println(faker.IntInRange(10, 20))
	fmt.Println(faker.IntInRange(-20, -10))
	fmt.Println(faker.IntInRange(-20, -30))
}
Output:

16
-14
-20

func LangCode

func LangCode() string

LangCode will build a random language code string.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(1101)
	fmt.Println(faker.LangCode())
}
Output:

sk

func LangName

func LangName() string

LangName will build a random language name string.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(1100)
	fmt.Println(faker.LangName())
}
Output:

Kirghiz

func LastName

func LastName() string

LastName will build a random last name string.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(1404)
	fmt.Println(faker.LastName())
}
Output:

Ankunding

func Letters

func Letters() string

Letters will build a random string of only letters of length between 1 and 8.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(905)
	fmt.Println(faker.Letters())
}
Output:

HZ

func LettersWithSize

func LettersWithSize(size int) string

LettersWithSize will build a random string of only letters of length size.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(904)
	fmt.Println(faker.LettersWithSize(7))
}
Output:

ZHCbqwV

func Lexify

func Lexify(str string) string

Lexify will replace all occurrences of "?" in str with a random letter.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(906)
	fmt.Println(faker.Lexify("ab?c??d?"))
}
Output:

abxcZhdZ

func MaleFirstName

func MaleFirstName() string

MaleFirstName will build a random male first name string.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(1400)
	fmt.Println(faker.MaleFirstName())
}
Output:

Lucien

func Minute

func Minute() int

Minute will build a random minute.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(47)
	fmt.Println(faker.Minute())
}
Output:

40

func Month

func Month() string

Month will build a random month string.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(51)
	fmt.Println(faker.Month())
}
Output:

July

func NameInitials

func NameInitials() string

NameInitials will build a random name initials of 2 characters string.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(1408)
	fmt.Println(faker.NameInitials())
}
Output:

NP

func NamePrefix

func NamePrefix() string

NamePrefix will build a random name prefix string.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(1405)
	fmt.Println(faker.NamePrefix())
}
Output:

Msgr.

func NameSuffix

func NameSuffix() string

NameSuffix will build a random name suffix string.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(1406)
	fmt.Println(faker.NameSuffix())
}
Output:

PhD

func NanoSecond

func NanoSecond() int

NanoSecond will build a random nano second.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(45)
	fmt.Println(faker.NanoSecond())
}
Output:

299642157

func NeutralFirstName

func NeutralFirstName() string

NeutralFirstName will build a random neutral first name string.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(1402)
	fmt.Println(faker.NeutralFirstName())
}
Output:

Hayden

func Numerify

func Numerify(str string) string

Numerify will replace all occurrences of "?" in str with a random digit.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(907)
	fmt.Println(faker.Numerify("ab?c??d???"))
}
Output:

ab5c30d754

func Paragraph

func Paragraph() string

Paragraph will build a random paragraph.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(1602)
	fmt.Println(faker.Paragraph())
}
Output:

A currant is a deer from the right perspective. Having been a gymnast, authors often misinterpret the tangerine as an intelligent camel, when in actuality it feels more like a communicative bear; As far as he is concerned, a shark is the zebra of a dog. Those kumquats are nothing more than elephants. It's an undeniable fact, really; some posit the hilarious prune to be less than intellectual. A communicative zebra's goat comes with it the thought that the honest snake is a cow? Washing and polishing the car,excited cranberries show us how grapefruits can be elephants. One cannot separate bears from dynamic cows! One cannot separate cats from stimulating spiders. Extending this logic, a goldfish can hardly be considered a succinct spider without also being a cheetah.

func ParagraphWithSentenceCount

func ParagraphWithSentenceCount(n int) string

ParagraphWithSentenceCount will build a random paragraph string consisting of n sentences.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(1601)
	fmt.Println(faker.ParagraphWithSentenceCount(5))
}
Output:

Their squirrel was, in this moment, an affable goat. A camel is a lion's panda! In modern times dazzling lemons show us how plums can be horses. This is not to discredit the idea that a cat can hardly be considered an amused fish without also being a lobster? An exuberant goldfish is a wolf of the mind.

func Parameterize

func Parameterize(str string) string

Parameterize replaces special characters in str so that it may be used as part of a 'pretty' URL.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(908)
	fmt.Println(faker.Parameterize("The Amazing Zanzò 153 "))
}
Output:

the-amazing-zanz-153

func PhoneNumber

func PhoneNumber() string

PhoneNumber will build a random phone number string.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(103)
	fmt.Println(faker.PhoneNumber())
}
Output:

152.380.7298

func Pick

func Pick(pool ...string) string

Pick returns a random string among those passed as parameters.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(909)
	fmt.Println(faker.Pick("cat", "dog", "mouse", "lion", "bear"))
}
Output:

dog

func RegisterBuilder

func RegisterBuilder(builderName, builderType string, fn builderFunc) error

RegisterBuilder register a new builder. A builder is a variadic function that will take an arbitrary number of strings as arguments and return an interface or an error. This function (builder) can be used to generate fake data. builderName is the name of the builder, builderType is the type of the interface returned by the builder.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(1802)

	// Define a new builder
	builder := func(params ...string) (interface{}, error) {
		if len(params) > 0 && params[0] == "melee" {
			return faker.Pick("Barbarian", "Bard", "Fighter", "Monk", "Paladin", "Rogue"), nil
		}
		return faker.Pick("Cleric", "Druid", "Ranger", "Sorcerer", "Warlock", "Wizard"), nil
	}

	// Register a new builder named "dndClass" for string type
	err := faker.RegisterBuilder("dndClass", "string", builder)
	if err != nil {
		panic(err)
	}

	player := &struct {
		Class string `faker:"dndClass(melee)"`
		// other fields ...
	}{}

	// Build a struct with fake data
	err = faker.Build(&player)
	if err != nil {
		panic(err)
	}

	fmt.Println(player.Class)
}
Output:

Paladin

func SafeEmail

func SafeEmail() string

SafeEmail will build a random email address string whose domain is always example.com.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(1704)
	fmt.Println(faker.SafeEmail())
}
Output:

disbelieve@example.com

func Sample added in v0.1.2

func Sample(slice interface{}) interface{}

Sample return a random element of slice. Sample panics if slice is not a slice, is nil or is empty.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(201)
	slice := []int{1, 2, 3, 4, 5}
	fmt.Println(faker.Sample(slice))
}
Output:

5

func Second

func Second() int

Second will build a random second.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(46)
	fmt.Println(faker.Second())
}
Output:

51

func Sentence

func Sentence() string

Sentence will build a random sentence string.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(1600)
	fmt.Println(faker.Sentence())
}
Output:

A knowledgeable pomegranate without peaches is truly a panda of compassionate sharks.

func SetPool

func SetPool(namespace, group string, pool Pool)

SetPool add a new Pool under the group group with namespace namespace (see GetData).

func SetPoolGroup

func SetPoolGroup(namespace string, poolGroup PoolGroup)

SetPoolGroup add a new PoolGroup under the namespace namespace (see GetData).

func SetRand

func SetRand(r *rand.Rand)

SetRand set a new source of random numbers (see rand.Rand). The default source is:

rand.New(rand.NewSource(time.Now().UnixNano()))

func SetSeed

func SetSeed(seed int64)

SetSeed uses the provided seed value to initialize the generator to a deterministic state (see rand.Seed).

func ShortBinaryGender

func ShortBinaryGender() string

ShortBinaryGender will build a random short binary gender string (m or f).

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(1502)
	fmt.Println(faker.ShortBinaryGender())
}
Output:

m

func Slice

func Slice(size int, fn func() interface{}) []interface{}

Slice will build a random slice of interface{} of length n. The elements of the slice are genereted by the function fn.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(200)
	fmt.Println(faker.Slice(3, func() interface{} { return faker.IntInRange(0, 10) }))
}
Output:

[6 9 9]

func Slug

func Slug() string

Slug will build a random slug string.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(1705)
	fmt.Println(faker.Slug())
}
Output:

a-reliable-seal-s-bee-comes-with-it-the-thought-that-the-adventurous-giraffe-is-an-alligator

func String

func String() string

String will build a random string of length between 1 and 8.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(901)
	fmt.Println(faker.String())
}
Output:

PMIWvi6i

func StringWithSize

func StringWithSize(size int) string

StringWithSize will build a random string of length size.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(900)
	fmt.Println(faker.StringWithSize(5))
}
Output:

zVCVi

func Time

func Time() time.Time

Time will build a random time.Time.

func TimeInRange

func TimeInRange(min, max time.Time) time.Time

TimeInRange will build a random time.Time between min and max included.

func TimeNow added in v1.7.2

func TimeNow() time.Time

TimeNow will build the current time.

func TimeZone

func TimeZone() string

TimeZone will build a random timezone string.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(53)
	fmt.Println(faker.TimeZone())
}
Output:

Venezuela Standard Time

func TimeZoneAbbr

func TimeZoneAbbr() string

TimeZoneAbbr will build a random abbreviated timezone string.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(54)
	fmt.Println(faker.TimeZoneAbbr())
}
Output:

MEDT

func TimeZoneFull

func TimeZoneFull() string

TimeZoneFull will build a random full timezone string.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(55)
	fmt.Println(faker.TimeZoneFull())
}
Output:

(UTC-03:00) Cayenne, Fortaleza

func TimeZoneOffset

func TimeZoneOffset() float32

TimeZoneOffset will build a random timezone offset.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(56)
	fmt.Println(faker.TimeZoneOffset())
}
Output:

-1

func TimeZoneRegion

func TimeZoneRegion() string

TimeZoneRegion will build a random timezone region string.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(57)
	fmt.Println(faker.TimeZoneRegion())
}
Output:

Africa/Accra

func URL

func URL() string

URL will build a random URL string.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(1706)
	fmt.Println(faker.URL())
}
Output:

https://www.mcmillon.info/this-could-be-or-perhaps-their-alligator-was-in-this-moment-an-eager-spider

func UUID

func UUID() string

UUID will build a random UUID string.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(104)
	fmt.Println(faker.UUID())
}
Output:

40abb44c-895e-45b8-9f67-cc02a811744a

func Uint

func Uint() uint

Uint will build a random uint.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(14)
	fmt.Println(faker.Uint())
}
Output:

2486533097

func Uint16

func Uint16() uint16

Uint16 will build a random uint16.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(20)
	fmt.Println(faker.Uint16())
}
Output:

29810

func Uint16InRange

func Uint16InRange(min, max uint16) uint16

Uint16InRange will build a random uint16 between min and max included.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(19)
	fmt.Println(faker.Uint16InRange(10, 20))
	fmt.Println(faker.Uint16InRange(20, 10))
}
Output:

13
20

func Uint32

func Uint32() uint32

Uint32 will build a random uint32.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(18)
	fmt.Println(faker.Uint32())
}
Output:

1185777406

func Uint32InRange

func Uint32InRange(min, max uint32) uint32

Uint32InRange will build a random uint32 between min and max included.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(17)
	fmt.Println(faker.Uint32InRange(10, 20))
	fmt.Println(faker.Uint32InRange(20, 10))
}
Output:

16
20

func Uint64

func Uint64() uint64

Uint64 will build a random uint64.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(16)
	fmt.Println(faker.Uint64())
}
Output:

16676020418646319060

func Uint64InRange

func Uint64InRange(min, max uint64) uint64

Uint64InRange will build a random uint64 between min and max included.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(15)
	fmt.Println(faker.Uint64InRange(10, 20))
	fmt.Println(faker.Uint64InRange(20, 10))
}
Output:

13
20

func Uint8

func Uint8() uint8

Uint8 will build a random uint8.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(22)
	fmt.Println(faker.Uint8())
}
Output:

231

func Uint8InRange

func Uint8InRange(min, max uint8) uint8

Uint8InRange will build a random uint8 between min and max included.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(21)
	fmt.Println(faker.Uint8InRange(10, 20))
	fmt.Println(faker.Uint8InRange(20, 10))
}
Output:

18
20

func UintInRange

func UintInRange(min, max uint) uint

UintInRange will build a random uint between min and max included.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(13)
	fmt.Println(faker.UintInRange(10, 20))
	fmt.Println(faker.UintInRange(20, 10))
}
Output:

15
20

func Uniq

func Uniq(group string, maxRetry int, fn func() (interface{}, error)) (interface{}, error)

Uniq run max maxRetry times fn function until fn returns a unique value for the group of runs group. Returns error if the number of runs reach maxRetry. If maxRetry is zero use default value that is 10000.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(403)
	generator := func() (interface{}, error) { return faker.IntInRange(0, 1), nil }
	value1, _ := faker.Uniq("test", 0, generator)
	fmt.Println(value1)
	value2, _ := faker.Uniq("test", 0, generator)
	fmt.Println(value2)
	faker.ClearUniqCache("test")
	value3, _ := faker.Uniq("test", 0, generator)
	fmt.Println(value3)
}
Output:

1
0
0

func UniqSlice

func UniqSlice(size int, group string, maxRetry int, fn func() (interface{}, error)) ([]interface{}, error)

UniqSlice run max maxRetry times fn function until fn returns a unique slice for the group of runs group. Returns error if the number of runs reach maxRetry. If maxRetry is zero use default value that is 10000.

func UnregisterBuilder

func UnregisterBuilder(builderName, builderType string) error

UnregisterBuilder unregister/remove a builder.

func Username

func Username() string

Username will build a random username string.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(1700)
	fmt.Println(faker.Username())
}
Output:

polychasium

func WeekDay

func WeekDay() string

WeekDay will build a random weekday string (Monday-Sunday).

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(50)
	fmt.Println(faker.WeekDay())
}
Output:

Saturday

func Year

func Year() int

Year will build a random year between 1900 - 2100.

Example
package main

import (
	"fmt"

	"github.com/pioz/faker"
)

func main() {
	faker.SetSeed(52)
	fmt.Println(faker.Year())
}
Output:

2032

Types

type Pool

type Pool []interface{}

Pool type is a slice that contains fake data.

type PoolData

type PoolData map[string]PoolGroup

PoolData type is a map that groups PoolGroup types.

type PoolGroup

type PoolGroup map[string]Pool

PoolGroup type is a map that groups Pool types.

Jump to

Keyboard shortcuts

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