Documentation
¶
Index ¶
- Constants
- Variables
- func FormatCamelCaseAdjNoun(adjective, noun string, digit int) string
- func FormatHyphenedAdjNoun(adjective, noun string, digit int) string
- func FormatPascalCaseAdjNoun(adjective, noun string, digit int) string
- func Generate() string
- func GenerateCamelCase() string
- func GenerateHyphened() string
- func GeneratePascalCase() 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 FormatCamelCaseAdjNoun ¶ added in v0.2.0
FormatCamelCaseAdjNoun formats an adjective, noun, and digit in the following way: bigCloud9
func FormatHyphenedAdjNoun ¶ added in v0.2.0
FormatHyphenedAdjNoun formats an adjective, noun, and digit in the following way: big-cloud-9
func FormatPascalCaseAdjNoun ¶ added in v0.2.0
FormatPascalCaseAdjNoun formats an adjective, noun, and digit in the following way: BigCloud9
func Generate ¶
func Generate() string
Generate fetches a random name of the default dictionary and format.
Example ¶
package main
import (
"fmt"
"github.com/marstr/randname"
)
func main() {
fmt.Println(randname.Generate())
}
Output:
func GenerateCamelCase ¶ added in v0.2.0
func GenerateCamelCase() string
GenerateCamelCase fetches a random name using the default dictionary, formatted like: bigCloud9
Example ¶
package main
import (
"fmt"
"github.com/marstr/randname"
)
func main() {
fmt.Println(randname.GenerateCamelCase())
}
Output:
func GenerateHyphened ¶ added in v0.2.0
func GenerateHyphened() string
GenerateHyphened fetches a random name using the default dictionary, formatted like: big-cloud-9
Example ¶
package main
import (
"fmt"
"github.com/marstr/randname"
)
func main() {
fmt.Println(randname.GenerateHyphened())
}
Output:
func GeneratePascalCase ¶ added in v0.2.0
func GeneratePascalCase() string
GeneratePascalCase fetches a random name using the default dictionary, formatted like: BigCloud9
Example ¶
package main
import (
"fmt"
"github.com/marstr/randname"
)
func main() {
fmt.Println(randname.GeneratePascalCase())
}
Output:
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.
func (AdjNoun) Generate ¶
Generate creates a new randomly generated name with the
Example ¶
package main
import (
"fmt"
"github.com/marstr/randname"
)
func main() {
generator := randname.NewAdjNoun()
fmt.Println(generator.Generate())
}
Output:
func (AdjNoun) GenerateCamelCase ¶ added in v0.2.0
GenerateCamelCase randomly generates an adjective, noun, and number combination using the provided dictionaries, then returns them as a string formatted like: bigCloud9
Example ¶
package main
import (
"fmt"
"github.com/marstr/randname"
)
func main() {
var generator randname.AdjNoun
fmt.Println(generator.GenerateCamelCase())
}
Output:
func (AdjNoun) GenerateHyphened ¶ added in v0.2.0
GenerateHyphened randomly generates an adjective, noun, and number combination using the provided dictionaries, then returns them as a string formatted like: big-cloud-9
Example ¶
package main
import (
"fmt"
"github.com/marstr/randname"
)
func main() {
var generator randname.AdjNoun
fmt.Println(generator.GenerateHyphened())
}
Output:
func (AdjNoun) GeneratePascalCase ¶ added in v0.2.0
GeneratePascalCase randomly generates an adjective, noun, and number then returns them as a string formatted like: BigCloud9
Example ¶
package main
import (
"fmt"
"github.com/marstr/randname"
)
func main() {
var generator randname.AdjNoun
fmt.Println(generator.GeneratePascalCase())
}
Output:
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: