petname

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2023 License: BSD-3-Clause Imports: 3 Imported by: 0

README

Alternative to dustinkirklands golang-petname.

Verify Go Reference

!The API is incompatible with dustinkirkland/golang-petname!

The goal is to provide a low overhead alternative that'S well-maintained and simple to work with.

Usage

Add to your dependencies:

go get github.com/Bios-Marcel/go-petname

Call the Generate function:

petname.Generate(3, petname.Lower, petname.Underscore)

You can change the wordlists by calling SetNames, SetAdjectives and SetAdverbs. Note that by default, the short package is used as the source of words for all groups. The other packages available are medium and long.

Technically you can provide your own lists.

Generate wordlists

The wordlists are generated like this:

go run ./cmd/generate folder > target/words.go

Replace folder with the folder that contains adjectives.txt, adverbs.txt and names.txt.

Documentation

Overview

Package petname is a library for generating human-readable, random names for objects (e.g. hostnames, containers, blobs).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Adjective

func Adjective() string

Adjective returns a random adjective from a list of petname adjectives.

func Adverb

func Adverb() string

Adverb returns a random adverb from a list of petname adverbs.

func Generate

func Generate(wordCount uint, casing Casing, separator Separator) string

Generate will create a petname using the given configuration. Casing and word separation are different, allowing things such as `Word-Word-Word` or `WORD_WORD_WORD`.

func Name

func Name() string

Name returns a random name from a list of petname names.

func NonDeterministicMode

func NonDeterministicMode()

NonDeterministicMode configures the local random generator used internally to provide non deterministic results, instead of a pre-defined order that is reproducible even after a process restart. If you wish to specify a custom contant, call [Seed(int64)].

func Seed

func Seed(seed int64)

Seed configures the local random generator, allowing you to specify a constant for reproducible "randomness" or provide a custom value for "true" randomness.

func SetAdjectives

func SetAdjectives(a []string)

SetAdjectives specifies which adjectives to use when generating petnames. Note that these are expected to be all lowercase characters and not containing any trailing or leading whitespace.

func SetAdverbs

func SetAdverbs(a []string)

SetAdverbs specifies which adverbs to use when generating petnames. Note that these are expected to be all lowercase characters and not containing any trailing or leading whitespace.

func SetNames

func SetNames(n []string)

SetNames specifies which names to use when generating petnames. Note that these are expected to be all lowercase characters and not containing any trailing or leading whitespace.

Types

type Casing

type Casing int

Casing specifies the casing of the overall petname, not its separate words.

const (
	// Lower will keep all letters as they are. Since the requirement for the
	// word lists is that they are all lowercase, this will result in a NO-OP.
	Lower Casing = iota
	// Upper will uppercase all letters.
	Upper
	// Title will uppercase the first letter and keep the rest lowercased..
	Title
)

type Separator

type Separator = byte

Separator specifies the separator between words in a petname.

const (
	None       Separator = 0
	Hyphen     Separator = '-'
	Underscore Separator = '_'
)

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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