Categorygithub.com/tinygg/gofaker
modulepackage
1.0.8
Repository: https://github.com/tinygg/gofaker.git
Documentation: pkg.go.dev

# README

alt text

gofaker Go Report Card Go codecov.io GoDoc license

Random data generator written in go

Buy Me A Coffee

Features

Installation

go get github.com/tinygg/gofaker

Example

import "github.com/tinygg/gofaker"

gofaker.Seed(0)

gofaker.Name()             // Markus Moen
gofaker.Email()            // [email protected]
gofaker.Phone()            // (570)245-7485
gofaker.BS()               // front-end
gofaker.BeerName()         // Duvel
gofaker.Color()            // MediumOrchid
gofaker.Company()          // Moen, Pagac and Wuckert
gofaker.CreditCardNumber() // 4287271570245748
gofaker.HackerPhrase()     // Connecting the array won't do anything, we need to generate the haptic COM driver!
gofaker.JobTitle()         // Director
gofaker.CurrencyShort()    // USD
// See full list below

Example Struct

import "github.com/tinygg/gofaker"

// Create structs with random injected data
type Foo struct {
	Bar      string
	Int      int
	Pointer  *int
	Name     string  `fake:"{firstname}"`   // Any available function all lowercase
	Sentence string  `fake:"{sentence:3}"`  // Can call with parameters
	RandStr  string  `fake:"{randomstring:[hello,world]}"`
	Number   string  `fake:"{number:1,10}"` // Comma separated for multiple values
	Skip     *string `fake:"skip"`          // Set to "skip" to not generate data for
}

type FooBar struct {
	Bars    []string `fake:"{name}"`              // Array of random size (1-10) with fake function applied
	Foos    []Foo    `fakesize:"3"`               // Array of size specified with faked struct
	FooBars []Foo    `fake:"{name}" fakesize:"3"` // Array of size 3 with fake function applied
}

// Pass your struct as a pointer
var f Foo
gofaker.Struct(&f)
fmt.Println(f.Bar)      // hrukpttuezptneuvunh
fmt.Println(f.Int)      // -7825289004089916589
fmt.Println(*f.Pointer) // -343806609094473732
fmt.Println(f.Name)     // fred
fmt.Println(f.Sentence) // Record river mind.
fmt.Println(f.RandStr)  // world
fmt.Println(f.Number)   // 4
fmt.Println(f.Skip)     // <nil>

var fb FooBar
gofaker.Struct(&fb)
fmt.Println(fb.Bars)      // [Charlie Senger]
fmt.Println(fb.Foos)      // [{blmfxy -2585154718894894116 0xc000317bc0 Emmy Attitude demand addition. hello 3 <nil>} {cplbf -1722374676852125164 0xc000317cb0 Viva Addition option link. hello 7 <nil>}]

Example Custom Functions

// Simple
AddFuncLookup("friendname", Info{
	Category:    "custom",
	Description: "Random friend name",
	Example:     "bill",
	Output:      "string",
	Call: func(m *map[string][]string, info *Info) (interface{}, error) {
		return RandomString([]string{"bill", "bob", "sally"}), nil
	},
})

// With Params
AddFuncLookup("jumbleword", Info{
	Category:    "jumbleword",
	Description: "Take a word and jumple it up",
	Example:     "loredlowlh",
	Output:      "string",
	Params: []Param{
		{Field: "word", Type: "int", Description: "Word you want to jumble"},
	},
	Call: func(m *map[string][]string, info *Info) (interface{}, error) {
		word, err := info.GetString(m, "word")
		if err != nil {
			return nil, err
		}

		split := strings.Split(word, "")
		ShuffleStrings(split)
		return strings.Join(split, ""), nil
	},
})

type Foo struct {
	FriendName string `fake:"{friendname}"`
	JumbleWord string `fake:"{jumbleword:helloworld}"`
}

var f Foo
Struct(&f)
fmt.Printf("%s", f.FriendName) // bill
fmt.Printf("%s", f.JumbleWord) // loredlowlh

Functions

File

JSON(jo *JSONOptions) []byte
XML(xo *XMLOptions) []byte
Extension() string
MimeType() string

Person

Person() *PersonInfo
Name() string
NamePrefix() string
NameSuffix() string
FirstName() string
LastName() string
Gender() string
SSN() string
Contact() *ContactInfo
Email() string
Phone() string
PhoneFormatted() string
Teams(people []string, teams []string) map[string][]string

Generate

Struct(v interface{})
Map() map[string]interface{}
Generate(value string) string

Auth

Username() string
Password(lower bool, upper bool, numeric bool, special bool, space bool, num int) string

Address

Address() *AddressInfo
City() string
Country() string
CountryAbr() string
State() string
StateAbr() string
Street() string
StreetName() string
StreetNumber() string
StreetPrefix() string
StreetSuffix() string
Zip() string
Latitude() float64
LatitudeInRange(min, max float64) (float64, error)
Longitude() float64
LongitudeInRange(min, max float64) (float64, error)

Game

Gamertag() string

Beer

BeerAlcohol() string
BeerBlg() string
BeerHop() string
BeerIbu() string
BeerMalt() string
BeerName() string
BeerStyle() string
BeerYeast() string

Cars

Vehicle() *VehicleInfo
CarMaker() string
CarModel() string
VehicleType() string
FuelType() string
TransmissionGearType() string

Words

Noun() string
Verb() string
Adverb() string
Preposition() string
Adjective() string
Word() string
Sentence(wordCount int) string
Paragraph(paragraphCount int, sentenceCount int, wordCount int, separator string) string
LoremIpsumWord() string
LoremIpsumSentence(wordCount int) string
LoremIpsumParagraph(paragraphCount int, sentenceCount int, wordCount int, separator string) string
Question() string
Quote() string
Phrase() string

Foods

Fruit() string
Vegetable() string
Breakfast() string
Lunch() string
Dinner() string
Snack() string
Dessert() string

Misc

Bool() bool
UUID() string

Colors

Color() string
HexColor() string
RGBColor() []int
SafeColor() string

Internet

URL() string
ImageURL(width int, height int) string
DomainName() string
DomainSuffix() string
IPv4Address() string
IPv6Address() string
StatusCode() string
SimpleStatusCode() int
LogLevel(logType string) string
HTTPMethod() string
UserAgent() string
ChromeUserAgent() string
FirefoxUserAgent() string
OperaUserAgent() string
SafariUserAgent() string

Date/Time

Date() time.Time
DateRange(start, end time.Time) time.Time
NanoSecond() int
Second() int
Minute() int
Hour() int
Month() string
Day() int
WeekDay() string
Year() int
TimeZone() string
TimeZoneAbv() string
TimeZoneFull() string
TimeZoneOffset() float32
TimeZoneRegion() string

Payment

Price(min, max float64) float64
CreditCard() *CreditCardInfo
CreditCardCvv() string
CreditCardExp() string
CreditCardNumber(*CreditCardOptions) string
CreditCardType() string
Currency() *CurrencyInfo
CurrencyLong() string
CurrencyShort() string
AchRouting() string
AchAccount() string
BitcoinAddress() string
BitcoinPrivateKey() string

Company

BS() string
BuzzWord() string
Company() string
CompanySuffix() string
Job() *JobInfo
JobDescriptor() string
JobLevel() string
JobTitle() string

Hacker

HackerAbbreviation() string
HackerAdjective() string
HackerIngverb() string
HackerNoun() string
HackerPhrase() string
HackerVerb() string

Hipster

HipsterWord() string
HipsterSentence(wordCount int) string
HipsterParagraph(paragraphCount int, sentenceCount int, wordCount int, separator string) string

App

AppName() string
AppVersion() string
AppAuthor() string

Animal

PetName() string
Animal() string
AnimalType() string
FarmAnimal() string
Cat() string
Dog() string

Emoji

Emoji() string // 🤣
EmojiDescription() string // winking face
EmojiCategory() string // Smileys & Emotion
EmojiAlias() string // smiley
EmojiTag() string // happy

Languages

Language() string
LanguageAbbreviation() string
ProgrammingLanguage() string
ProgrammingLanguageBest() string

Numbers

Number(min int, max int) int
Int8() int8
Int16() int16
Int32() int32
Int64() int64
Uint8() uint8
Uint16() uint16
Uint32() uint32
Uint64() uint64
Float32() float32
Float32Range(min, max float32) float32
Float64() float64
Float64Range(min, max float64) float64
ShuffleInts(a []int)
RandomInt(i []int) int

String

Digit() string
Letter() string
Lexify(str string) string
Numerify(str string) string
ShuffleStrings(a []string)
RandomString(a []string) string

# Packages

No description provided by the author
No description provided by the author

# Functions

AchAccount will generate a 12 digit account number.
AchRouting will generate a 9 digit routing number.
AddFuncLookup takes a field and adds it to map.
Address will generate a struct of address information.
Adjective will generate a random adjective.
Adverb will generate a random adverb.
Animal will return a random animal.
AnimalType will return a random animal type.
AppAuthor will generate a random company or person name.
AppName will generate a random app name.
AppVersion will generate a random app version.
BeerAlcohol will return a random beer alcohol level between 2.0 and 10.0.
BeerBlg will return a random beer blg between 5.0 and 20.0.
BeerHop will return a random beer hop.
BeerIbu will return a random beer ibu value between 10 and 100.
BeerMalt will return a random beer malt.
BeerName will return a random beer name.
BeerStyle will return a random beer style.
BeerYeast will return a random beer yeast.
BitcoinAddress will generate a random bitcoin address consisting of numbers, upper and lower characters.
BitcoinPrivateKey will generate a random bitcoin private key consisting of numbers, upper and lower characters.
Bool will generate a random boolean value.
Breakfast will return a random breakfast name.
BS will generate a random company bs string.
BuzzWord will generate a random company buzz word string.
Car will generate a struct with car information.
CarFuelType will return a random fuel type.
CarMaker will return a random car maker.
CarModel will return a random car model.
CarTransmissionType will return a random transmission type.
CarType will generate a random car type string.
Cat will return a random cat breed.
Categories will return a map string array of available data categories and sub categories.
ChromeUserAgent will generate a random chrome browser user agent string.
City will generate a random city string.
Color will generate a random color string.
Company will generate a random company name string.
CompanySuffix will generate a random company suffix string.
Contact will generate a struct with information randomly populated contact information.
Country will generate a random country string.
CountryAbr will generate a random abbreviated country string.
CreditCard will generate a struct full of credit card information.
CreditCardCvv will generate a random CVV number Its a string because you could have 017 as an exp date.
CreditCardExp will generate a random credit card expiration date string Exp date will always be a future date.
CreditCardNumber will generate a random luhn credit card number.
CreditCardType will generate a random credit card type string.
CSV generates an object or an array of objects in json format.
Currency will generate a struct with random currency information.
CurrencyLong will generate a random long currency name.
CurrencyShort will generate a random short currency value.
Date will generate a random time.Time struct.
DateRange will generate a random time.Time struct between a start and end date.
Day will generate a random day between 1 - 31.
Dessert will return a random dessert name.
Digit will generate a single ASCII digit.
Dinner will return a random dinner name.
Dog will return a random dog breed.
DomainName will generate a random url domain name.
DomainSuffix will generate a random domain suffix.
Email will generate a random email string.
Emoji will return a random fun emoji.
EmojiAlias will return a random fun emoji alias.
EmojiCategory will return a random fun emoji category.
EmojiDescription will return a random fun emoji description.
EmojiTag will return a random fun emoji tag.
FarmAnimal will return a random animal that usually lives on a farm.
FileExtension will generate a random file extension.
FileMimeType will generate a random mime file type.
FirefoxUserAgent will generate a random firefox broswer user agent string.
FirstName will generate a random first name.
Float32 will generate a random float32 value.
Float32Range will generate a random float32 value between min and max.
Float64 will generate a random float64 value.
Float64Range will generate a random float64 value between min and max.
Fruit will return a random fruit name.
Gamertag will generate a random video game username.
Gender will generate a random gender string.
Generate fake information from given string.
GetFuncLookup will lookup.
HackerAbbreviation will return a random hacker abbreviation.
HackerAdjective will return a random hacker adjective.
HackeringVerb will return a random hacker ingverb.
HackerNoun will return a random hacker noun.
HackerPhrase will return a random hacker sentence.
HackerVerb will return a random hacker verb.
HexColor will generate a random hexadecimal color string.
HipsterParagraph will generate a random paragraphGenerator Set Paragraph Count Set Sentence Count Set Word Count Set Paragraph Separator.
HipsterSentence will generate a random sentence.
HipsterWord will return a single hipster word.
Hour will generate a random hour - in military time.
HTTPMethod will generate a random http method.
HTTPStatusCode will generate a random status code.
HTTPStatusCodeSimple will generate a random simple status code.
Image generates a random rgba image.
ImageJpeg generates a random rgba jpeg image.
ImagePng generates a random rgba png image.
ImageURL will generate a random Image Based Upon Height And Width.
Int16 will generate a random int16 value.
Int32 will generate a random int32 value.
Int64 will generate a random int64 value.
Int8 will generate a random Int8 value.
IPv4Address will generate a random version 4 ip address.
IPv6Address will generate a random version 6 ip address.
Job will generate a struct with random job information.
JobDescriptor will generate a random job descriptor string.
JobLevel will generate a random job level string.
JobTitle will generate a random job title string.
JSON generates an object or an array of objects in json format.
Language will return a random language.
LanguageAbbreviation will return a random language abbreviation.
LastName will generate a random last name.
Latitude will generate a random latitude float64.
LatitudeInRange will generate a random latitude within the input range.
Letter will generate a single random lower case ASCII letter.
Lexify will replace ? will random generated letters.
LogLevel will generate a random log level See data/LogLevels for list of available levels.
Longitude will generate a random longitude float64.
LongitudeInRange will generate a random longitude within the input range.
LoremIpsumParagraph will generate a random paragraphGenerator.
LoremIpsumSentence will generate a random sentence.
LoremIpsumWord will generate a random word.
Lunch will return a random lunch name.
MacAddress will generate a random mac address.
Map will generate a random set of map data.
Minute will generate a random minute.
Month will generate a random month string.
Name will generate a random First and Last Name.
NamePrefix will generate a random name prefix.
NameSuffix will generate a random name suffix.
NanoSecond will generate a random nano second.
NewChooser initializes a new Chooser consisting of the possible Choices.
Noun will generate a random noun.
Number will generate a random number between given min And max.
Numerify will replace # with random numerical values.
OperaUserAgent will generate a random opera browser user agent string.
Paragraph will generate a random paragraphGenerator.
Password will generate a random password Minimum number length of 5 if less than.
Person will generate a struct with person information.
PetName will return a random fun pet name.
Phone will generate a random phone number string.
PhoneFormatted will generate a random phone number string.
Phrase will return a random dictionary phrase.
Preposition will generate a random preposition.
Price will take in a min and max value and return a formatted price.
ProgrammingLanguage will return a random programming language.
ProgrammingLanguageBest will return a random programming language.
Question will return a random question.
Quote will return a random quote from a random person.
RandomInt will take in a slice of int and return a randomly selected value.
RandomString will take in a slice of string and return a randomly selected value.
RandomUint will take in a slice of uint and return a randomly selected value.
Regex will generate a string based upon a RE2 syntax.
RemoveFuncLookup will remove a function from lookup.
RGBColor will generate a random int slice color.
SafariUserAgent will generate a random safari browser user agent string.
SafeColor will generate a random safe color string.
Second will generate a random second.
Seed random.
Sentence will generate a random sentence.
ShuffleInts will randomize a slice of ints.
ShuffleStrings will randomize a slice of strings.
Snack will return a random snack name.
SSN will generate a random Social Security Number.
State will generate a random state string.
StateAbr will generate a random abbreviated state string.
Street will generate a random address street string.
StreetName will generate a random address street name string.
StreetNumber will generate a random address street number string.
StreetPrefix will generate a random address street prefix string.
StreetSuffix will generate a random address street suffix string.
Struct fills in exported elements of a struct with random data based on the value of `fake` tag of exported elements.
Teams takes in an array of people and team names and randomly places the people into teams as evenly as possible.
TimeZone will select a random timezone string.
TimeZoneAbv will select a random timezone abbreviation string.
TimeZoneFull will select a random full timezone string.
TimeZoneOffset will select a random timezone offset.
TimeZoneRegion will select a random region style timezone string, e.g.
Uint16 will generate a random uint16 value.
Uint32 will generate a random uint32 value.
Uint64 will generate a random uint64 value.
Uint8 will generate a random uint8 value.
URL will generate a random url string.
UserAgent will generate a random broswer user agent.
Username will genrate a random username based upon picking a random lastname and random numbers at the end.
UUID (version 4) will generate a random unique identifier based upon random nunbers Format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.
Vegetable will return a random vegetable name.
Verb will generate a random verb.
WeekDay will generate a random weekday string (Monday-Sunday).
Word will generate a random word.
XML generates an object or an array of objects in json format.
Year will generate a random year between 1900 - current year.
Zip will generate a random Zip code string.

# Variables

FuncLookups is the primary map array with mapping to all available data.

# Structs

AddressInfo is a struct full of address information.
CarInfo is a struct dataset of all car information.
Choice is a generic wrapper that can be used to add weights for any object.
A Chooser caches many possible Choices in a structure designed to improve performance on repeated calls for weighted random selection.
ContactInfo struct full of contact info.
CreditCardInfo is a struct containing credit variables.
CreditCardOptions is the options for credit card number.
CSVOptions defines values needed for csv generation.
CurrencyInfo is a struct of currency information.
Field is used for defining what name and function you to generate for file outuputs.
Info structures fields to better break down what each one generates.
JobInfo is a struct of job information.
JSONOptions defines values needed for json generation.
Param is a breakdown of param requirements and type definition.
PersonInfo is a struct of person information.
XMLOptions defines values needed for json generation.