项目作者: Pallinder

项目描述 :
A tiny generator of random data for golang, also known as a faker
高级语言: Go
项目地址: git://github.com/Pallinder/go-randomdata.git
创建时间: 2013-07-30T23:17:29Z
项目社区:https://github.com/Pallinder/go-randomdata

开源协议:MIT License

下载


go-randomdata

contributions welcome
GoDoc
Build Status
Go Report Card

randomdata is a tiny help suite for generating random data such as

  • first names (male or female)
  • last names
  • full names (male or female)
  • country names (full name or iso 3166.1 alpha-2 or alpha-3)
  • locales / language tags (bcp-47)
  • random email address
  • city names
  • American state names (two chars or full)
  • random numbers (in an interval)
  • random paragraphs
  • random bool values
  • postal- or zip-codes formatted for a range of different countries.
  • american sounding addresses / street names
  • silly names - suitable for names of things
  • random days
  • random months
  • random full date
  • random full profile
  • random date inside range
  • random phone number

Installation

go get github.com/Pallinder/go-randomdata

Usage

  1. package main
  2. import (
  3. "fmt"
  4. "github.com/Pallinder/go-randomdata"
  5. )
  6. func main() {
  7. // Print a random silly name
  8. fmt.Println(randomdata.SillyName())
  9. // Print a male title
  10. fmt.Println(randomdata.Title(randomdata.Male))
  11. // Print a female title
  12. fmt.Println(randomdata.Title(randomdata.Female))
  13. // Print a title with random gender
  14. fmt.Println(randomdata.Title(randomdata.RandomGender))
  15. // Print a male first name
  16. fmt.Println(randomdata.FirstName(randomdata.Male))
  17. // Print a female first name
  18. fmt.Println(randomdata.FirstName(randomdata.Female))
  19. // Print a last name
  20. fmt.Println(randomdata.LastName())
  21. // Print a male name
  22. fmt.Println(randomdata.FullName(randomdata.Male))
  23. // Print a female name
  24. fmt.Println(randomdata.FullName(randomdata.Female))
  25. // Print a name with random gender
  26. fmt.Println(randomdata.FullName(randomdata.RandomGender))
  27. // Print an email
  28. fmt.Println(randomdata.Email())
  29. // Print a country with full text representation
  30. fmt.Println(randomdata.Country(randomdata.FullCountry))
  31. // Print a country using ISO 3166-1 alpha-2
  32. fmt.Println(randomdata.Country(randomdata.TwoCharCountry))
  33. // Print a country using ISO 3166-1 alpha-3
  34. fmt.Println(randomdata.Country(randomdata.ThreeCharCountry))
  35. // Print BCP 47 language tag
  36. fmt.Println(randomdata.Locale())
  37. // Print a currency using ISO 4217
  38. fmt.Println(randomdata.Currency())
  39. // Print the name of a random city
  40. fmt.Println(randomdata.City())
  41. // Print the name of a random american state
  42. fmt.Println(randomdata.State(randomdata.Large))
  43. // Print the name of a random american state using two chars
  44. fmt.Println(randomdata.State(randomdata.Small))
  45. // Print an american sounding street name
  46. fmt.Println(randomdata.Street())
  47. // Print an american sounding address
  48. fmt.Println(randomdata.Address())
  49. // Print a random number >= 10 and < 20
  50. fmt.Println(randomdata.Number(10, 20))
  51. // Print a number >= 0 and < 20
  52. fmt.Println(randomdata.Number(20))
  53. // Print a random float >= 0 and < 20 with decimal point 3
  54. fmt.Println(randomdata.Decimal(0, 20, 3))
  55. // Print a random float >= 10 and < 20
  56. fmt.Println(randomdata.Decimal(10, 20))
  57. // Print a random float >= 0 and < 20
  58. fmt.Println(randomdata.Decimal(20))
  59. // Print a bool
  60. fmt.Println(randomdata.Boolean())
  61. // Print a paragraph
  62. fmt.Println(randomdata.Paragraph())
  63. // Print a postal code
  64. fmt.Println(randomdata.PostalCode("SE"))
  65. // Print a set of 2 random numbers as a string
  66. fmt.Println(randomdata.StringNumber(2, "-"))
  67. // Print a set of 2 random 3-Digits numbers as a string
  68. fmt.Println(randomdata.StringNumberExt(2, "-", 3))
  69. // Print a random string sampled from a list of strings
  70. fmt.Println(randomdata.StringSample("my string 1", "my string 2", "my string 3"))
  71. // Print a valid random IPv4 address
  72. fmt.Println(randomdata.IpV4Address())
  73. // Print a valid random IPv6 address
  74. fmt.Println(randomdata.IpV6Address())
  75. // Print a browser's user agent string
  76. fmt.Println(randomdata.UserAgentString())
  77. // Print a day
  78. fmt.Println(randomdata.Day())
  79. // Print a month
  80. fmt.Println(randomdata.Month())
  81. // Print full date like Monday 22 Aug 2016
  82. fmt.Println(randomdata.FullDate())
  83. // Print full date <= Monday 22 Aug 2016
  84. fmt.Println(randomdata.FullDateInRange("2016-08-22"))
  85. // Print full date >= Monday 01 Aug 2016 and <= Monday 22 Aug 2016
  86. fmt.Println(randomdata.FullDateInRange("2016-08-01", "2016-08-22"))
  87. // Print phone number according to e.164
  88. fmt.Println(randomdata.PhoneNumber())
  89. // Get a complete and randomised profile of data generally used for users
  90. // There are many fields in the profile to use check the Profile struct definition in fullprofile.go
  91. profile := randomdata.GenerateProfile(randomdata.Male | randomdata.Female | randomdata.RandomGender)
  92. fmt.Printf("The new profile's username is: %s and password (md5): %s\n", profile.Login.Username, profile.Login.Md5)
  93. // Get a random country-localised street name for Great Britain
  94. fmt.Println(randomdata.StreetForCountry("GB"))
  95. // Get a random country-localised street name for USA
  96. fmt.Println(randomdata.StreetForCountry("US"))
  97. // Get a random country-localised province for Great Britain
  98. fmt.Println(randomdata.ProvinceForCountry("GB"))
  99. // Get a random country-localised province for USA
  100. fmt.Println(randomdata.ProvinceForCountry("US"))
  101. }

Versioning / Release Strategy

Go-Randomdata follows Semver

You can find current releases tagged under the releases section.

The CHANGELOG.md file contains the changelog of the project.

Contributors

All the other contributors are listed here.