idgen

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package idgen produces identifiers.

These identifiers have the following properties:

Index

Constants

This section is empty.

Variables

View Source
var RE = regexp.MustCompile(fmt.Sprintf("[%s]{%d}", zBase32Alphabet, divCeil(idBytes*8, 5)))

RE is a (fragment of) a regular expression that matches a possible ID.

Functions

func ID

func ID(ctx context.Context) string

ID generates an ID using the generator from the given context.

func WithGenerator

func WithGenerator(ctx context.Context, generator Generator) context.Context

WithGenerator returns a cloned context.Context with the given Generator injected into it.

Types

type Generator

type Generator interface {
	// ID generates a new unique identifier
	ID() string
}

Generator is a generator of unique identifiers.

var Random Generator = randomGenerator{}

Random is the global ID generator that produces random identifiers.

func FromContext

func FromContext(ctx context.Context) Generator

FromContext returns the Generator that WithGenerator has injected into the context.

func NewConstant

func NewConstant(id string) Generator

NewConstant returns new generator that produces a constant ID once.

func NewDeterministic

func NewDeterministic(key string) Generator

NewDeterministic creates new deterministic ID generator. Generators with the same key will produce exactly the same identifier sequences.

Jump to

Keyboard shortcuts

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