gonomen

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 6, 2026 License: MIT Imports: 3 Imported by: 0

README

gonomen

CI codecov Go Report Card Go Reference Go Version Repo Size

A Go library for generating readable, multilingual usernames — like HappyRiver4821 or feliz-luna9k3.

Combines a random adjective and noun from a curated word list, formats them in your preferred casing style, and appends an optional suffix. Zero external dependencies.

Install

go get github.com/DRiotTech/gonomen

Quick start

import "github.com/DRiotTech/gonomen"

// Defaults: English, CamelCase, 4-digit suffix
g := gonomen.NewGenerator(gonomen.GeneratorOptions{})
fmt.Println(g.Generate()) // e.g. "HappyRiver4821"

Options

g := gonomen.NewGenerator(gonomen.GeneratorOptions{
    Language:     "it",                       // ISO 639-1 code; default "en"
    Case:         gonomen.KebabCase,          // default CamelCase
    SuffixLength: 6,                          // default 4; 0 to disable
    SuffixType:   gonomen.SuffixAlphanumeric, // default SuffixDigits
})
fmt.Println(g.Generate()) // e.g. "felice-mare9k3a2b"
Fluent builder

The generator is immutable — each With* call returns a new copy.

base := gonomen.NewGenerator(gonomen.GeneratorOptions{})

snake := base.WithCase(gonomen.SnakeCase).WithSuffixLength(0)
kebab := base.WithCase(gonomen.KebabCase).WithLanguage("es")

fmt.Println(snake.Generate()) // e.g. "happy_river"
fmt.Println(kebab.Generate()) // e.g. "feliz-luna4821"

Casing formats

Constant Example
CamelCase (default) HappyRiver
LowerCamelCase happyRiver
SnakeCase happy_river
KebabCase happy-river
Lower happyriver
Upper HAPPYRIVER

Suffix types

Constant Example
SuffixDigits (default) 4821
SuffixAlphanumeric 4a2z

Pass SuffixLength: 0 to generate a bare word pair with no suffix.

Supported languages

Code Language
en English
el Greek (ASCII transliteration)
es Spanish
it Italian
pl Polish (ASCII transliteration)
pt Portuguese

Unsupported language codes silently fall back to English.

Collision resistance

Each language ships 100 adjectives × 100 nouns. With the default 4-digit suffix that gives 100,000,000 unique combinations per language — sufficient for most use cases without any uniqueness check on the caller side.

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Case

type Case string

Case represents the casing format for generated usernames.

const (
	CamelCase      Case = "camel"      // AdjectiveNoun
	LowerCamelCase Case = "lowerCamel" // adjectiveNoun
	SnakeCase      Case = "snake"      // adjective_noun
	KebabCase      Case = "kebab"      // adjective-noun
	Lower          Case = "lower"      // adjectivenoun
	Upper          Case = "upper"      // ADJECTIVENOUN
)

type Generator

type Generator struct {
	// contains filtered or unexported fields
}

Generator generates random usernames according to its configuration. It is immutable: builder methods return a new copy.

func NewGenerator

func NewGenerator(opts GeneratorOptions) Generator

NewGenerator creates a Generator from the provided options. Zero values use defaults: language "en", CamelCase, 4 digit suffix.

func (Generator) Generate

func (g Generator) Generate() string

Generate returns a randomly generated username.

func (Generator) WithCase

func (g Generator) WithCase(c Case) Generator

WithCase returns a new Generator with the given case format.

func (Generator) WithLanguage

func (g Generator) WithLanguage(lang Language) Generator

WithLanguage returns a new Generator for the given language (ISO 639-1 code). Falls back to "en" if the language is unsupported.

func (Generator) WithSuffixLength

func (g Generator) WithSuffixLength(n int) Generator

WithSuffixLength returns a new Generator with the given suffix length. Pass 0 to disable the suffix entirely.

func (Generator) WithSuffixType

func (g Generator) WithSuffixType(st SuffixType) Generator

WithSuffixType returns a new Generator with the given suffix type.

type GeneratorOptions

type GeneratorOptions struct {
	Language     Language   // default: EN
	Case         Case       // default: CamelCase
	SuffixLength int        // number of suffix characters; default 4
	SuffixType   SuffixType // default: SuffixDigits
}

GeneratorOptions configures a Generator at creation time.

type Language

type Language string

Language identifies a supported word-list language (ISO 639-1 code). Supported values: "en", "el", "es", "it", "pl", "pt".

type SuffixType

type SuffixType string

SuffixType controls what characters are appended after the word pair.

const (
	SuffixDigits       SuffixType = "digits"       // e.g. 4821
	SuffixAlphanumeric SuffixType = "alphanumeric" // e.g. 4a2z
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL