fake

package module
v0.0.0-...-96070b0 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2017 License: MIT Imports: 16 Imported by: 0

README

Fake

Build Status GoDoc License Go Report Card

Fake is a fake data generator for Go (Golang), heavily inspired by the forgery and ffaker Ruby gems. This particular branch is a fork from icrowley with improvements merged from the community.

About

Most data and methods are ported from forgery/ffaker Ruby gems. For the list of available methods, please look at GoDoc.

Currently, English and Russian are available. English is the default. If the selected language does not implement the required data, then English will be returned as a fallback. This may be disabled by calling EnFallback(false).

Fake stores the raw data in line-delimited files under data/, which is subdivided by language. By default, fake uses a gzip'd representation of the filesystem generated by mjibson/esc. Embedding the data removes external file dependencies during runtime, and compression gives a small space gain. Decompressed files are cached after first access.

If the sample data is changed or new data is added, data.go must be regenerated. If you are using Go >=1.4, then a simple go generate will handle it. Otherwise, you must get mjibson/esc and run esc -o data.go -pkg fake data.

Fake can load the files directly from the filesystem by calling UseExternalData(true).

Examples

Basic data:

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

Select non-English language:

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

Remove English fallback:

err := fake.SetLang("ru")
if err != nil {
  panic(err)
}
fake.EnFallback(false)
password := fake.Paragraph() // returns a blank string because Paragraph() is not implemented in Russian

Use external data:

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

Credit

The common English wordlist located in data/en/words is from Wiktionary, licensed under the Creative Commons Attribution-ShareAlike License

Documentation

Overview

Package fake is a fake data generator, heavily inspired by the forgery and ffaker Ruby gems. Most data and methods are ported from forgery/ffaker Ruby gems.

Currently, English and Russian are available. English is the default. If the selected language does not implement the required data, then English will be returned as a fallback. This may be disabled by calling `EnFallback(false)`.

Fake stores the raw data in line-delimited files under data/, which is subdivided by language. By default, fake uses a gzip'd representation of the filesystem generated by https://github.com/mjibson/esc. Embedding the data removes external file dependencies during runtime, and compression gives a small space gain. Decompressed files are cached after first access.

If the sample data is changed or new data is added, `data.go` must be regenerated. If you are using Go >=1.4, then a simple `go generate` will handle it. Otherwise, you must get https://github.com/mjibson/esc and run `esc -o data.go -pkg fake data`.

Fake can load the files directly from the filesystem by calling `UseExternalData(true)`.

Examples

Basic data:

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

Select non-English language:

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

Remove English fallback:

err := fake.SetLang("ru")
if err != nil {
    panic(err)
}
fake.EnFallback(false)
password := fake.Paragraph() // returns a blank string because Paragraph() is not implemented in Russian

Use external data:

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

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrNoLanguage indicates that the given language is not available
	ErrNoLanguage = errors.New("Language unavailable")
	// ErrNoSamples indicates that there are no samples for the given language
	ErrNoSamples = errors.New("No samples found for given language")
)

Functions

func Amount

func Amount() float32

func Between

func Between(from, to int) int

func Birthdate

func Birthdate(age int) time.Time

Birthdate returns a date of birth for someone of the given age

func Bool

func Bool() bool

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 Choose

func Choose(v ...interface{}) interface{}

Choose selects a random item from the given set

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 vendor's card number rules. Currently supports amex, discover, mastercard, and visa.

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 Education

func Education() string

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 Ethnicities

func Ethnicities(n int) (a []string)

func Ethnicity

func Ethnicity() string

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 LatitudeDegrees

func LatitudeDegrees() int

LatitudeDegrees generates latitude degrees (from -180 to 180)

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 Latitute

func Latitute() float32

Latitute generates latitude

func Longitude

func Longitude() float32

Longitude generates longitude

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 MaritalStatus

func MaritalStatus() string

MaritalStatus returns its namesake

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 Question

func Question() string

func Religion

func Religion() string

func Religions

func Religions(n int) (a []string)

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, and returns ErrNoLanguage if lang doesn't exist

func SexualOrientation

func SexualOrientation() string

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 Time

func Time(from, to time.Time) time.Time

Time generates a time.Time between 'from' and 'to'.

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 Toss

func Toss() int

Toss returns either a true or false

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 Version

func Version() string

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 WordsNUnique

func WordsNUnique(n int) []string

WordsNUnique generates n unique 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