names

package
v0.1.0-alpha.3 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package names provides human-readable name assignment for workers. Names are generated using a Docker-like approach: adjective + noun combinations. This provides a large variety of unique, memorable names.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateName

func GenerateName() string

GenerateName creates a random name by combining an adjective and a noun. Format: "adjective_noun" (e.g., "brave_einstein", "clever_curie")

func GetAllAdjectives

func GetAllAdjectives() []string

GetAllAdjectives returns the full list of adjectives.

func GetAllNouns

func GetAllNouns() []string

GetAllNouns returns the full list of nouns.

func GetCombinationCount

func GetCombinationCount() int

GetCombinationCount returns the total number of possible name combinations.

func GetNextAvailableName

func GetNextAvailableName(ctx context.Context, db DB) (string, error)

GetNextAvailableName returns a unique name that is not currently in use. It generates random adjective_noun combinations until it finds one that's available. Returns empty string if it fails to generate a unique name after many attempts (extremely unlikely given the large combination space).

func ParseName

func ParseName(name string) (adjective, noun string)

ParseName splits a name into its adjective and noun components. Returns empty strings if the name is not in the expected format.

func ReleaseName

func ReleaseName(_ context.Context, _ DB, _ string) error

ReleaseName is a no-op in the current implementation since names are automatically released when a work is completed or failed (they're excluded from the used names query). This function is provided for API completeness.

Types

type DB

type DB interface {
	QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
}

DB is the interface required for name operations.

type DefaultGenerator

type DefaultGenerator struct{}

DefaultGenerator is the default implementation of the Generator interface.

func (*DefaultGenerator) GetNextAvailableName

func (g *DefaultGenerator) GetNextAvailableName(ctx context.Context, db DB) (string, error)

GetNextAvailableName implements Generator.

type Generator

type Generator interface {
	GetNextAvailableName(ctx context.Context, db DB) (string, error)
}

Generator is the interface for name generation operations.

func NewGenerator

func NewGenerator() Generator

NewGenerator creates a new DefaultGenerator.

type GeneratorMock

type GeneratorMock struct {
	// GetNextAvailableNameFunc mocks the GetNextAvailableName method.
	GetNextAvailableNameFunc func(ctx context.Context, db DB) (string, error)
	// contains filtered or unexported fields
}

GeneratorMock is a mock implementation of Generator.

func TestSomethingThatUsesGenerator(t *testing.T) {

	// make and configure a mocked Generator
	mockedGenerator := &GeneratorMock{
		GetNextAvailableNameFunc: func(ctx context.Context, db DB) (string, error) {
			panic("mock out the GetNextAvailableName method")
		},
	}

	// use mockedGenerator in code that requires Generator
	// and then make assertions.

}

func (*GeneratorMock) GetNextAvailableName

func (mock *GeneratorMock) GetNextAvailableName(ctx context.Context, db DB) (string, error)

GetNextAvailableName calls GetNextAvailableNameFunc.

func (*GeneratorMock) GetNextAvailableNameCalls

func (mock *GeneratorMock) GetNextAvailableNameCalls() []struct {
	Ctx context.Context
	Db  DB
}

GetNextAvailableNameCalls gets all the calls that were made to GetNextAvailableName. Check the length with:

len(mockedGenerator.GetNextAvailableNameCalls())

Jump to

Keyboard shortcuts

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