fake

package module
v0.1.11 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2025 License: MIT Imports: 10 Imported by: 1

README ΒΆ

πŸ“ Fake - Go Fake Data Generator

This is a fork of the original icrowley/fake with native go:embed support and without global variables.

Key Improvements

  • ✨ Native Go embed (no code generation needed)
  • πŸš€ No globals, no mutexes etc...

Features

  • Multi-language support

Installation

go get github.com/dirtymew/fake

Quick Start


func main(){
    f := fake.New()
    fmt.Println(f.FullName())                  // "John Doe" 
    fmt.Println(f.EmailAddress())              // "john.doe@example.com"
}

Requirements

Go 1.24+


Documentation ΒΆ

Index ΒΆ

Constants ΒΆ

View Source
const (
	LangEnglish = "en"
	LangRussian = "ru"
)
View Source
const (
	DefaultPasswordMinLength = 6
	DefaultPasswordMaxLength = 12
	HexColorLength           = 6
	HexColorShortLength      = 3
)

Variables ΒΆ

View Source
var (
	// ErrNoLanguageFn is the error that indicates that given language is not available
	ErrNoLanguageFn = func(lang string) error { return fmt.Errorf("language passed (%s) is not available", lang) }
	// ErrNoSamplesFn is the error that indicates that there are no samples for the given language
	ErrNoSamplesFn = func(lang string) error { return fmt.Errorf("no samples found for language: %s", lang) }
)

Functions ΒΆ

This section is empty.

Types ΒΆ

type Fake ΒΆ

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

func New ΒΆ

func New() *Fake

func (*Fake) Brand ΒΆ

func (f *Fake) Brand() string

Brand generates brand name

func (*Fake) Character ΒΆ

func (f *Fake) Character() string

Character generates random character in the given language

func (*Fake) Characters ΒΆ

func (f *Fake) Characters() string

Characters generates from 1 to 5 characters in the given language

func (*Fake) CharactersN ΒΆ

func (f *Fake) CharactersN(n int) string

CharactersN generates n random characters in the given language

func (*Fake) City ΒΆ

func (f *Fake) City() string

City generates random city

func (*Fake) Color ΒΆ

func (f *Fake) Color() string

Color generates color name

func (*Fake) Company ΒΆ

func (f *Fake) Company() string

Company generates company name

func (*Fake) Continent ΒΆ

func (f *Fake) Continent() string

Continent generates random continent

func (*Fake) Country ΒΆ

func (f *Fake) Country() string

Country generates random country

func (*Fake) CreditCardNum ΒΆ

func (f *Fake) CreditCardNum(vendor string) string

CreditCardNum generated credit card number according to the card number rules

func (*Fake) CreditCardType ΒΆ

func (f *Fake) CreditCardType() string

CreditCardType returns one of the following credit values: VISA, MasterCard, American Express and Discover

func (*Fake) Currency ΒΆ

func (f *Fake) Currency() string

Currency generates currency name

func (*Fake) CurrencyCode ΒΆ

func (f *Fake) CurrencyCode() string

CurrencyCode generates currency code

func (*Fake) Day ΒΆ

func (f *Fake) Day() int

Day generates day of the month

func (*Fake) Digits ΒΆ

func (f *Fake) Digits() string

Digits returns from 1 to 5 digits as a string

func (*Fake) DigitsN ΒΆ

func (f *Fake) DigitsN(n int) string

DigitsN returns n digits as a string

func (*Fake) DomainName ΒΆ

func (f *Fake) DomainName() string

DomainName generates random domain name

func (*Fake) DomainZone ΒΆ

func (f *Fake) DomainZone() string

DomainZone generates random domain zone

func (*Fake) EmailAddress ΒΆ

func (f *Fake) EmailAddress() string

EmailAddress generates email address

func (*Fake) EmailBody ΒΆ

func (f *Fake) EmailBody() string

EmailBody generates random email body

func (*Fake) EmailSubject ΒΆ

func (f *Fake) EmailSubject() string

EmailSubject generates random email subject

func (*Fake) EnFallback ΒΆ

func (f *Fake) EnFallback(flag bool)

EnFallback sets the flag that allows fake to fallback to englsh samples if the ones for the used languaged are not available

func (*Fake) FemaleFirstName ΒΆ

func (f *Fake) FemaleFirstName() string

FemaleFirstName generates female first name

func (*Fake) FemaleFullName ΒΆ

func (f *Fake) FemaleFullName() string

FemaleFullName generates female full name it can occasionally include prefix or suffix

func (*Fake) FemaleFullNameWithPrefix ΒΆ

func (f *Fake) FemaleFullNameWithPrefix() string

FemaleFullNameWithPrefix generates prefixed female full name if prefixes for the given language are available

func (*Fake) FemaleFullNameWithSuffix ΒΆ

func (f *Fake) FemaleFullNameWithSuffix() string

FemaleFullNameWithSuffix generates suffixed female full name if suffixes for the given language are available

func (*Fake) FemaleLastName ΒΆ

func (f *Fake) FemaleLastName() string

FemaleLastName generates female last name

func (*Fake) FemalePatronymic ΒΆ

func (f *Fake) FemalePatronymic() string

FemalePatronymic generates female patronymic

func (*Fake) FirstName ΒΆ

func (f *Fake) FirstName() string

FirstName generates first name

func (*Fake) FullName ΒΆ

func (f *Fake) FullName() string

FullName generates full name it can occasionally include prefix or suffix

func (*Fake) FullNameWithPrefix ΒΆ

func (f *Fake) FullNameWithPrefix() string

FullNameWithPrefix generates prefixed full name if prefixes for the given language are available

func (*Fake) FullNameWithSuffix ΒΆ

func (f *Fake) FullNameWithSuffix() string

FullNameWithSuffix generates suffixed full name if suffixes for the given language are available

func (*Fake) Gender ΒΆ

func (f *Fake) Gender() string

Gender generates random gender

func (*Fake) GenderAbbrev ΒΆ

func (f *Fake) GenderAbbrev() string

GenderAbbrev returns first downcased letter of the random gender

func (*Fake) GetLangs ΒΆ added in v0.1.2

func (f *Fake) GetLangs() []string

GetLangs returns a slice of available languages from the embedded data FS.

func (*Fake) HexColor ΒΆ

func (f *Fake) HexColor() string

HexColor generates hex color name

func (*Fake) HexColorShort ΒΆ

func (f *Fake) HexColorShort() string

HexColorShort generates short hex color name

func (*Fake) IPv4 ΒΆ

func (f *Fake) IPv4() string

IPv4 generates IPv4 address

func (*Fake) IPv6 ΒΆ

func (f *Fake) IPv6() string

IPv6 generates IPv6 address

func (*Fake) Industry ΒΆ

func (f *Fake) Industry() string

Industry generates industry name

func (*Fake) JobTitle ΒΆ

func (f *Fake) JobTitle() string

JobTitle generates job title

func (*Fake) Language ΒΆ

func (f *Fake) Language() string

Language generates random human language

func (*Fake) LastName ΒΆ

func (f *Fake) LastName() string

LastName generates last name

func (*Fake) Latitude ΒΆ

func (f *Fake) Latitude() float32

Latitude generates latitude (from -90.0 to 90.0)

func (*Fake) LatitudeDegrees ΒΆ

func (f *Fake) LatitudeDegrees() int

LatitudeDegrees generates latitude degrees (from -90 to 90)

func (*Fake) LatitudeDirection ΒΆ

func (f *Fake) LatitudeDirection() string

LatitudeDirection generates latitude direction (N(orth) o S(outh))

func (*Fake) LatitudeMinutes ΒΆ

func (f *Fake) LatitudeMinutes() int

LatitudeMinutes generates latitude minutes (from 0 to 60)

func (*Fake) LatitudeSeconds ΒΆ

func (f *Fake) LatitudeSeconds() int

LatitudeSeconds generates latitude seconds (from 0 to 60)

func (*Fake) Longitude ΒΆ

func (f *Fake) Longitude() float32

Longitude generates longitude (from -180 to 180)

func (*Fake) LongitudeDegrees ΒΆ

func (f *Fake) LongitudeDegrees() int

LongitudeDegrees generates longitude degrees (from -180 to 180)

func (*Fake) LongitudeDirection ΒΆ

func (f *Fake) LongitudeDirection() string

LongitudeDirection generates (W(est) or E(ast))

func (*Fake) LongitudeMinutes ΒΆ

func (f *Fake) LongitudeMinutes() int

LongitudeMinutes generates (from 0 to 60)

func (*Fake) LongitudeSeconds ΒΆ

func (f *Fake) LongitudeSeconds() int

LongitudeSeconds generates (from 0 to 60)

func (*Fake) MaleFirstName ΒΆ

func (f *Fake) MaleFirstName() string

MaleFirstName generates male first name

func (*Fake) MaleFullName ΒΆ

func (f *Fake) MaleFullName() string

MaleFullName generates male full name it can occasionally include prefix or suffix

func (*Fake) MaleFullNameWithPrefix ΒΆ

func (f *Fake) MaleFullNameWithPrefix() string

MaleFullNameWithPrefix generates prefixed male full name if prefixes for the given language are available

func (*Fake) MaleFullNameWithSuffix ΒΆ

func (f *Fake) MaleFullNameWithSuffix() string

MaleFullNameWithSuffix generates suffixed male full name if suffixes for the given language are available

func (*Fake) MaleLastName ΒΆ

func (f *Fake) MaleLastName() string

MaleLastName generates male last name

func (*Fake) MalePatronymic ΒΆ

func (f *Fake) MalePatronymic() string

MalePatronymic generates male patronymic

func (*Fake) Model ΒΆ

func (f *Fake) Model() string

Model generates model name that consists of letters and digits, optionally with a hyphen between them

func (*Fake) Month ΒΆ

func (f *Fake) Month() string

Month generates month name

func (*Fake) MonthNum ΒΆ

func (f *Fake) MonthNum() int

MonthNum generates month number (from 1 to 12)

func (*Fake) MonthShort ΒΆ

func (f *Fake) MonthShort() string

MonthShort generates abbreviated month name

func (*Fake) Paragraph ΒΆ

func (f *Fake) Paragraph() string

Paragraph generates paragraph

func (*Fake) Paragraphs ΒΆ

func (f *Fake) Paragraphs() string

Paragraphs generates from 1 to 5 paragraphs

func (*Fake) ParagraphsN ΒΆ

func (f *Fake) ParagraphsN(n int) string

ParagraphsN generates n paragraphs

func (*Fake) Password ΒΆ

func (f *Fake) Password(atLeast, atMost int, allowUpper, allowNumeric, allowSpecial bool) string

Password generates password with the length from atLeast to atMost characters, allow* parameters specify whether corresponding symbols can be used

Example:

f := fake.New()
password := f.Password(8, 16, true, true, true)
// Generates password like "Abc123!@"

func (*Fake) Patronymic ΒΆ

func (f *Fake) Patronymic() string

Patronymic generates patronymic

func (*Fake) Phone ΒΆ

func (f *Fake) Phone() string

Phone generates random phone number using one of the formats format specified in phone_format file

func (*Fake) Phonef ΒΆ added in v0.1.11

func (f *Fake) Phonef(format string) string

Phonef generates random phone number using format like #-###-###-##-##

func (*Fake) Product ΒΆ

func (f *Fake) Product() string

Product generates product title as brand + product name

func (*Fake) ProductName ΒΆ

func (f *Fake) ProductName() string

ProductName generates product name

func (*Fake) Seed ΒΆ

func (f *Fake) Seed(seed int64)

Seed uses the provided seed value to initialize the internal PRNG to a deterministic state.

func (*Fake) Sentence ΒΆ

func (f *Fake) Sentence() string

Sentence generates random sentence

func (*Fake) Sentences ΒΆ

func (f *Fake) Sentences() string

Sentences generates from 1 to 5 random sentences

func (*Fake) SentencesN ΒΆ

func (f *Fake) SentencesN(n int) string

SentencesN generates n random sentences

func (*Fake) SetLang ΒΆ

func (f *Fake) SetLang(newLang string) error

SetLang sets the language in which the data should be generated returns error if passed language is not available

func (*Fake) SimplePassword ΒΆ

func (f *Fake) SimplePassword() string

SimplePassword is a wrapper around Password, it generates password with the length from 6 to 12 symbols, with upper characters and numeric symbols allowed

func (*Fake) State ΒΆ

func (f *Fake) State() string

State generates random state

func (*Fake) StateAbbrev ΒΆ

func (f *Fake) StateAbbrev() string

StateAbbrev generates random state abbreviation

func (*Fake) Street ΒΆ

func (f *Fake) Street() string

Street generates random street name

func (*Fake) StreetAddress ΒΆ

func (f *Fake) StreetAddress() string

StreetAddress generates random street name along with building number

func (*Fake) Title ΒΆ

func (f *Fake) Title() string

Title generates from 2 to 5 titleized words

func (*Fake) TopLevelDomain ΒΆ

func (f *Fake) TopLevelDomain() string

TopLevelDomain generates random top level domain

func (*Fake) UseExternalFS ΒΆ added in v0.1.2

func (f *Fake) UseExternalFS(fs fs.FS)

func (*Fake) UserName ΒΆ

func (f *Fake) UserName() string

UserName generates user name in one of the following forms first name + last name, letter + last names or concatenation of from 1 to 3 lowercased words

func (*Fake) WeekDay ΒΆ

func (f *Fake) WeekDay() string

WeekDay generates name ot the week day

func (*Fake) WeekDayShort ΒΆ

func (f *Fake) WeekDayShort() string

WeekDayShort generates abbreviated name of the week day

func (*Fake) WeekdayNum ΒΆ

func (f *Fake) WeekdayNum() int

WeekdayNum generates number of the day of the week

func (*Fake) Word ΒΆ

func (f *Fake) Word() string

Word generates random word

func (*Fake) Words ΒΆ

func (f *Fake) Words() string

Words generates from 1 to 5 random words

func (*Fake) WordsN ΒΆ

func (f *Fake) WordsN(n int) string

WordsN generates n random words

func (*Fake) Year ΒΆ

func (f *Fake) Year(from, to int) int

Year generates year using the given boundaries

func (*Fake) Zip ΒΆ

func (f *Fake) Zip() string

Zip generates random zip code using one of the formats specifies in zip_format file

Jump to

Keyboard shortcuts

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