Documentation ¶
Overview ¶
The generators package contains a generator with a number of functions for the generation of words, sentences, paragraphs, male and female names, domains, URLs and e-mails and more. They generator creation takes a Rand as parameter. SimpleRand() produces one based on the current time and FixedRand() always the same. That way the generation of test data in larger scenarios can be repeated.
Index ¶
- Constants
- func BuildEMail(first, last, domain string) string
- func FixedRand() *rand.Rand
- func SimpleRand() *rand.Rand
- func ToUpperFirst(s string) string
- type Generator
- func (g *Generator) Domain() string
- func (g *Generator) Duration(lo, hi time.Duration) time.Duration
- func (g *Generator) EMail() string
- func (g *Generator) FemaleName() (first, middle, last string)
- func (g *Generator) FlipCoin(percent int) bool
- func (g *Generator) Int(lo, hi int) int
- func (g *Generator) Ints(lo, hi, count int) []int
- func (g *Generator) LimitedWord(lo, hi int) string
- func (g *Generator) MaleName() (first, middle, last string)
- func (g *Generator) OneByteOf(values ...byte) byte
- func (g *Generator) OneIntOf(values ...int) int
- func (g *Generator) OneRuneOf(values string) rune
- func (g *Generator) OneStringOf(values ...string) string
- func (g *Generator) Paragraph() string
- func (g *Generator) Pattern(pattern string) string
- func (g *Generator) Percent() int
- func (g *Generator) Sentence() string
- func (g *Generator) Time(loc *time.Location, base time.Time, dur time.Duration) time.Time
- func (g *Generator) URL() string
- func (g *Generator) Word() string
- func (g *Generator) Words(count int) []string
Constants ¶
const ( // MinWordLen is the length of the shortest word. MinWordLen = 1 // MaxWordLen is the length of the longest word. MaxWordLen = 14 )
Variables ¶
This section is empty.
Functions ¶
func BuildEMail ¶
BuildEMail creates an e-mail address out of first and last name and the domain.
func FixedRand ¶
FixedRand returns a random number generator with a fixed source so that tests using the generate functions can be repeated with the same result.
func SimpleRand ¶
SimpleRand returns a random number generator with a source using the the current time as seed. It's not the best random, but ok to generate test data.
func ToUpperFirst ¶
ToUpperFirst returns the passed string with the first rune converted to uppercase.
Types ¶
type Generator ¶
type Generator struct {
// contains filtered or unexported fields
}
Generator is responsible for generating different random data based on a random number generator.
func (*Generator) Duration ¶
Duration generates a duration between lo and hi including those values.
func (*Generator) FemaleName ¶
FemaleName generates a female name consisting out of first, middle and last name.
func (*Generator) FlipCoin ¶
FlipCoin returns true if the internal generated percentage is equal or greater than the passed percentage.
func (*Generator) LimitedWord ¶
LimitedWord generates a random word with a length between lo and hi.
func (*Generator) MaleName ¶
MaleName generates a male name consisting out of first, middle and last name.
func (*Generator) OneStringOf ¶
OneIStringOf returns one of the passed strings.
func (*Generator) Pattern ¶
Pattern generates a string based on a pattern. Here different escape chars are replaced by according random chars while all others are left as they are. Escape chars start with a caret (^) followed by specializer. Those are:
- ^ for a caret - 0 for a number between 0 and 9 - 1 for a number between 1 and 9 - o for an octal number - h for a hexadecimal number (lower-case) - H for a hexadecimal number (upper-case) - a for any char between a and z - A for any char between A and Z - c for a consonant (lower-case) - C for a consonant (upper-case) - v for a vowel (lower-case) - V for a vowel (upper-case)
func (*Generator) Sentence ¶
Sentence generates a sentence between 2 and 15 words and possibly containing commas.
func (*Generator) Time ¶
Time generates a time between the given one and that time plus the given duration. The result will have the passed location.