fake

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2020 License: MIT Imports: 16 Imported by: 0

README

Build Status Godoc license

Fake

Fake is a fake data generator for Go (Golang), heavily inspired by the forgery and ffaker Ruby gems.

About

Most data and methods are ported from forgery/ffaker Ruby gems. For the list of available methods please look at https://godoc.org/github.com/icrowley/fake. Currently english and russian languages are available. French is in progress, inspired by the Python lib "Faker".

Fake embeds samples data files unless you call UseExternalData(true) in order to be able to work without external files dependencies when compiled, so, if you add new data files or make changes to existing ones don't forget to regenerate data.go file using github.com/mjibson/esc tool and esc -o data.go -pkg fake data command (or you can just use go generate command if you are using Go 1.4 or later).

Install

go get github.com/icrowley/fake

Import

import (
  "github.com/icrowley/fake"
)

Documentation

Documentation can be found at godoc:

https://godoc.org/github.com/icrowley/fake

Test

To run the project tests:

cd test
go test

Examples

name := fake.FirstName()
fullname := fake.FullName()
product := fake.Product()

Changing language:

err := fake.SetLang("ru")
if err != nil {
  panic(err)
}
password := fake.SimplePassword()

Using english fallback:

err := fake.SetLang("ru")
if err != nil {
  panic(err)
}
fake.EnFallback(true)
password := fake.Paragraph()

Using external data:

fake.UseExternalData(true)
password := fake.Paragraph()
Author

Dmitry Afanasyev, http://twitter.com/i_crowley dimarzio1986@gmail.com

Maintainers

Dmitry Moskowski https://github.com/corpix

Documentation

Overview

Package fake is the fake data generatror for go (Golang), heavily inspired by forgery and ffaker Ruby gems

Most data and methods are ported from forgery/ffaker Ruby gems.

Currently english and russian languages are available.

For the list of available methods please look at https://godoc.org/github.com/icrowley/fake.

Fake embeds samples data files unless you call UseExternalData(true) in order to be able to work without external files dependencies when compiled, so, if you add new data files or make changes to existing ones don't forget to regenerate data.go file using github.com/mjibson/esc tool and esc -o data.go -pkg fake data command (or you can just use go generate command if you are using Go 1.4 or later).

Examples:

name := fake.FirstName()
fullname = := fake.FullName()
product := fake.Product()

Changing language:

err := fake.SetLang("ru")
if err != nil {
	panic(err)
}
password := fake.SimplePassword()

Using english fallback:

err := fake.SetLang("ru")
if err != nil {
	panic(err)
}
fake.EnFallback(true)
password := fake.Paragraph()

Using external data:

fake.UseExternalData(true)
password := fake.Paragraph()

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoLanguageFn is the error that indicates that given language is not available
	ErrNoLanguageFn = func(lang string) error { return fmt.Errorf("The 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

func Brand

func Brand() string

Brand generates brand name

func Character

func Character() string

Character generates random character in the given language

func Characters

func Characters() string

Characters generates from 1 to 5 characters in the given language

func CharactersN

func CharactersN(n int) string

CharactersN generates n random characters in the given language

func City

func City() string

City generates random city

func Color

func Color() string

Color generates color name

func Company

func Company() string

Company generates company name

func Continent

func Continent() string

Continent generates random continent

func Country

func Country() string

Country generates random country

func CreditCardNum

func CreditCardNum(vendor string) string

CreditCardNum generated credit card number according to the card number rules

func CreditCardType

func CreditCardType() string

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

func Currency

func Currency() string

Currency generates currency name

func CurrencyCode

func CurrencyCode() string

CurrencyCode generates currency code

func Day

func Day() int

Day generates day of the month

func Digits

func Digits() string

Digits returns from 1 to 5 digits as a string

func DigitsN

func DigitsN(n int) string

DigitsN returns n digits as a string

func Dir

func Dir(useLocal bool, name string) http.FileSystem

Dir returns a http.Filesystem for the embedded assets on a given prefix dir. If useLocal is true, the filesystem's contents are instead used.

func DomainName

func DomainName() string

DomainName generates random domain name

func DomainZone

func DomainZone() string

DomainZone generates random domain zone

func EmailAddress

func EmailAddress() string

EmailAddress generates email address

func EmailBody

func EmailBody() string

EmailBody generates random email body

func EmailSubject

func EmailSubject() string

EmailSubject generates random email subject

func EnFallback

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

func FS(useLocal bool) http.FileSystem

FS returns a http.Filesystem for the embedded assets. If useLocal is true, the filesystem's contents are instead used.

func FSByte

func FSByte(useLocal bool, name string) ([]byte, error)

FSByte returns the named file from the embedded assets. If useLocal is true, the filesystem's contents are instead used.

func FSMustByte

func FSMustByte(useLocal bool, name string) []byte

FSMustByte is the same as FSByte, but panics if name is not present.

func FSMustString

func FSMustString(useLocal bool, name string) string

FSMustString is the string version of FSMustByte.

func FSString

func FSString(useLocal bool, name string) (string, error)

FSString is the string version of FSByte.

func FemaleFirstName

func FemaleFirstName() string

FemaleFirstName generates female first name

func FemaleFullName

func FemaleFullName() string

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

func FemaleFullNameWithPrefix

func FemaleFullNameWithPrefix() string

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

func FemaleFullNameWithSuffix

func FemaleFullNameWithSuffix() string

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

func FemaleLastName

func FemaleLastName() string

FemaleLastName generates female last name

func FemalePatronymic

func FemalePatronymic() string

FemalePatronymic generates female patronymic

func FirstName

func FirstName() string

FirstName generates first name

func FullName

func FullName() string

FullName generates full name it can occasionally include prefix or suffix

func FullNameWithPrefix

func FullNameWithPrefix() string

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

func FullNameWithSuffix

func FullNameWithSuffix() string

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

func Gender

func Gender() string

Gender generates random gender

func GenderAbbrev

func GenderAbbrev() string

GenderAbbrev returns first downcased letter of the random gender

func GetLangs

func GetLangs() []string

GetLangs returns a slice of available languages

func HexColor

func HexColor() string

HexColor generates hex color name

func HexColorShort

func HexColorShort() string

HexColorShort generates short hex color name

func IPv4

func IPv4() string

IPv4 generates IPv4 address

func IPv6

func IPv6() string

IPv6 generates IPv6 address

func Industry

func Industry() string

Industry generates industry name

func JobTitle

func JobTitle() string

JobTitle generates job title

func Language

func Language() string

Language generates random human language

func LastName

func LastName() string

LastName generates last name

func Latitude

func Latitude() float32

Latitude generates latitude (from -90.0 to 90.0)

func LatitudeDegrees

func LatitudeDegrees() int

LatitudeDegrees generates latitude degrees (from -90 to 90)

func LatitudeDirection

func LatitudeDirection() string

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

func LatitudeMinutes

func LatitudeMinutes() int

LatitudeMinutes generates latitude minutes (from 0 to 60)

func LatitudeSeconds

func LatitudeSeconds() int

LatitudeSeconds generates latitude seconds (from 0 to 60)

func Longitude

func Longitude() float32

Longitude generates longitude (from -180 to 180)

func LongitudeDegrees

func LongitudeDegrees() int

LongitudeDegrees generates longitude degrees (from -180 to 180)

func LongitudeDirection

func LongitudeDirection() string

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

func LongitudeMinutes

func LongitudeMinutes() int

LongitudeMinutes generates (from 0 to 60)

func LongitudeSeconds

func LongitudeSeconds() int

LongitudeSeconds generates (from 0 to 60)

func MaleFirstName

func MaleFirstName() string

MaleFirstName generates male first name

func MaleFullName

func MaleFullName() string

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

func MaleFullNameWithPrefix

func MaleFullNameWithPrefix() string

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

func MaleFullNameWithSuffix

func MaleFullNameWithSuffix() string

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

func MaleLastName

func MaleLastName() string

MaleLastName generates male last name

func MalePatronymic

func MalePatronymic() string

MalePatronymic generates male patronymic

func Model

func Model() string

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

func Month

func Month() string

Month generates month name

func MonthNum

func MonthNum() int

MonthNum generates month number (from 1 to 12)

func MonthShort

func MonthShort() string

MonthShort generates abbreviated month name

func Paragraph

func Paragraph() string

Paragraph generates paragraph

func Paragraphs

func Paragraphs() string

Paragraphs generates from 1 to 5 paragraphs

func ParagraphsN

func ParagraphsN(n int) string

ParagraphsN generates n paragraphs

func Password

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

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

func Patronymic

func Patronymic() string

Patronymic generates patronymic

func Phone

func Phone() string

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

func Product

func Product() string

Product generates product title as brand + product name

func ProductName

func ProductName() string

ProductName generates product name

func Seed

func Seed(seed int64)

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

func Sentence

func Sentence() string

Sentence generates random sentence

func Sentences

func Sentences() string

Sentences generates from 1 to 5 random sentences

func SentencesN

func SentencesN(n int) string

SentencesN generates n random sentences

func SetLang

func SetLang(newLang string) error

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

func SimplePassword

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

func State() string

State generates random state

func StateAbbrev

func StateAbbrev() string

StateAbbrev generates random state abbreviation

func Street

func Street() string

Street generates random street name

func StreetAddress

func StreetAddress() string

StreetAddress generates random street name along with building number

func Title

func Title() string

Title generates from 2 to 5 titleized words

func TopLevelDomain

func TopLevelDomain() string

TopLevelDomain generates random top level domain

func UseExternalData

func UseExternalData(flag bool)

UseExternalData sets the flag that allows using of external files as data providers (fake uses embedded ones by default)

func UserAgent

func UserAgent() string

UserAgent generates a random user agent.

func UserName

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

func WeekDay() string

WeekDay generates name ot the week day

func WeekDayShort

func WeekDayShort() string

WeekDayShort generates abbreviated name of the week day

func WeekdayNum

func WeekdayNum() int

WeekdayNum generates number of the day of the week

func Word

func Word() string

Word generates random word

func Words

func Words() string

Words generates from 1 to 5 random words

func WordsN

func WordsN(n int) string

WordsN generates n random words

func Year

func Year(from, to int) int

Year generates year using the given boundaries

func Zip

func Zip() string

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

Types

This section is empty.

Jump to

Keyboard shortcuts

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