identifier

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package identifier provides a simple, thread-safe, and efficient way to generate unique identifiers. It offers straightforward functions to get unique strings or numbers without requiring any configuration.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateNumber added in v1.1.0

func GenerateNumber() (int64, error)

GenerateNumber generates a new identifier number using the default generator.

func GenerateString added in v1.1.0

func GenerateString() (string, error)

GenerateString generates a new identifier string using the default generator.

func Register

func Register(g Generator)

Register makes a generator available by name. If Register is called twice with the same name or if the generator is nil, it panics.

func Validate added in v1.4.0

func Validate(id any) bool

Validate checks if the provided id is a valid identifier using the default generator.

Types

type Generator

type Generator interface {
	// Name returns the unique name of the generator algorithm.
	Name() string
	// GenerateString generates a new identifier as a string.
	GenerateString() (string, error)
	// GenerateNumber generates a new identifier as an int64.
	// Note: May not be supported by all generators.
	GenerateNumber() (int64, error)
	// Validate checks if a provided identifier is valid.
	// The id can be a string or int64, depending on the generator.
	Validate(id any) bool
}

Generator defines the interface for an identifier generation algorithm. This is intended for advanced users who want to implement or use custom generators.

func Get

func Get(name string) Generator

Get returns the generator with the given name. It returns nil if no generator is registered with that name.

Directories

Path Synopsis
snowflake module

Jump to

Keyboard shortcuts

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