Documentation ¶
Index ¶
- Constants
- Variables
- func Generate() string
- func GenerateCamelCaseAdjNoun(adjective, noun string, digit int) string
- func GenerateHyphenedAdjNoun(adjective, noun string, digit int) string
- func GeneratePascalCaseAdjNoun(adjective, noun string, digit int) string
- func GenerateWithPrefix(prefix string, characters uint8) string
- type AdjNoun
- type AdjNounFormat
- type FileDictionaryBuilder
- type Prefixed
Examples ¶
Constants ¶
const PrefixedDefaultLen = uint8(6)
PrefixedDefaultLen is the number of characters that will be appended to a suffix if no length was specified.
Variables ¶
var ArabicNumerals = []rune{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'}
ArabicNumerals contains the numeric digits 0-9.
var LowercaseAlphabet = []rune{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'}
LowercaseAlphabet contains each letter of the alphaber, in lowercase.
var PrefixedDefaultAcceptable = append(append(append([]rune{}, ArabicNumerals...), UppercaseAlphabet...), LowercaseAlphabet...)
PrefixedDefaultAcceptable contains the characters that will be tacked onto the end of the Prefix, if none were provided.
var SpecialCharacters = []rune{'^', '$', '#', '*', '(', ')', '%', '@'}
SpecialCharacters holds a host of standard special characters.
var UppercaseAlphabet = []rune{'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'}
UppercaseAlphabet contains each letter of the alphabet, in uppercase.
Functions ¶
func Generate ¶
func Generate() string
generate fetches a random name of the default format and strategy.
func GenerateCamelCaseAdjNoun ¶
GenerateCamelCaseAdjNoun formats an adjective, noun, and digit in the following way: bigCloud9
func GenerateHyphenedAdjNoun ¶
GenerateHyphenedAdjNoun formats an adjective, noun, and digit in the following way: big-cloud-9
func GeneratePascalCaseAdjNoun ¶
GeneratePascalCaseAdjNoun formats an adjective, noun, and digit in the following way: BigCloud9
func GenerateWithPrefix ¶
GenerateWithPrefix generates a string with a given prefix then a given number of randomly selected characters.
Example ¶
package main import ( "fmt" "github.com/marstr/randname" ) func main() { for i := 0; i < 10; i++ { fmt.Println(randname.GenerateWithPrefix("randname-", 10)) } }
Output:
Types ¶
type AdjNoun ¶
type AdjNoun struct { Adjectives *collection.Dictionary Format AdjNounFormat Nouns *collection.Dictionary RandGenerator io.Reader }
AdjNoun creates a random name of the form adjectiveNameDigit
func NewAdjNoun ¶
func NewAdjNoun() *AdjNoun
NewAdjNoun creates a new instance of AdjNoun that is populated with all of the defaults.
type AdjNounFormat ¶
AdjNounFormat is a type of function that aggregates an Adjective, Noun, and Digit into a single formatted string.
type FileDictionaryBuilder ¶
type FileDictionaryBuilder struct {
Target string
}
FileDictionaryBuilder read words from a file.
func (FileDictionaryBuilder) Build ¶
func (fdb FileDictionaryBuilder) Build(dict *collection.Dictionary) (err error)
Build walks a simple newline delimited file of words and populates a dictionary with them.
type Prefixed ¶
Prefixed offers a means of generating a random name by providing a prefix, followed by a number of random letters or numbers.
Example ¶
package main import ( "fmt" "github.com/marstr/randname" ) func main() { generator := randname.Prefixed{ Prefix: "randname-", Acceptable: randname.ArabicNumerals, Len: 10, } for i := 0; i < 10; i++ { fmt.Println(generator.Generate()) } }
Output:
func (Prefixed) Generate ¶
Generate creates a string starting with a prefix, and ending with an assortment of randomly chosen runes.
Example ¶
package main import ( "fmt" "github.com/marstr/randname" ) func main() { generator := randname.Prefixed{ Prefix: "randnameRocks", } fmt.Println(generator.Generate()) }
Output: