identifier

package
v0.3.21 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2025 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package identifier provides a unified interface for generating and validating unique identifiers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(p Provider)

Register registers a provider, making it available via Get(). This function should be called from the init() function of each algorithm's package.

Types

type Generator

type Generator[T ~int64 | ~string] interface {
	Identifier
	// Generate creates a new identifier of type T.
	Generate() T
	// Validate checks if the provided value is a valid identifier of type T.
	Validate(T) bool
}

Generator defines a unified, generic interface for generating identifiers of a specific type. This is the interface that consuming code will typically interact with after initialization.

func Get

func Get[T ~string | ~int64](name string) Generator[T]

Get retrieves a typed generator by name from the registry. This is the primary, recommended entry point for getting a shared generator instance. It returns a ready-to-use, typed generator, or nil if the named provider doesn't exist or doesn't support the requested type (string or int64).

type Identifier

type Identifier interface {
	Name() string // Name returns the name of the identifier.
	Size() int    // Size returns the size of the identifier in bits.
}

Identifier defines the basic interface for all identifier types.

type Provider

type Provider interface {
	Identifier
	// AsString returns a string-based generator. Returns nil if not supported.
	AsString() Generator[string]
	// AsNumber returns a number-based generator. Returns nil if not supported.
	AsNumber() Generator[int64]
}

Provider is an interface for an algorithm that can provide generators for different types. A single provider can vend either a string or a number generator, or both.

Jump to

Keyboard shortcuts

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