nextid

package
v0.4.10 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2026 License: MIT Imports: 6 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package nextid generates the next task ID from existing ID lists.

It supports sequential, prefixed, random, and ULID formats while preserving common prefixes and zero-padding patterns.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GeneratePrefixed

func GeneratePrefixed(existingIDs []string, prefix string, padding int) string

GeneratePrefixed produces the next sequential ID with the given prefix. It filters existing IDs by prefix, finds the max numeric suffix, and returns prefix + zero-padded(max+1).

func GenerateRandom

func GenerateRandom(existingIDs []string, length int) (string, error)

GenerateRandom produces a random base-36 alphanumeric lowercase ID of the given length. It retries on collision with existingIDs (max 100 attempts).

func GenerateULID

func GenerateULID(existingIDs []string, length int) (string, error)

GenerateULID produces a ULID: 48-bit millisecond timestamp + 80-bit crypto random, encoded as 26 Crockford Base32 characters (lowercase). When length > 0 and < 26, the result is shortened to that length by dropping low-order timestamp characters and trailing random characters, always keeping some randomness. It retries on collision with existingIDs (max 100 attempts).

Types

type Result

type Result struct {
	NextID  string `json:"next_id" yaml:"next_id"`
	MaxID   string `json:"max_id" yaml:"max_id"`
	Prefix  string `json:"prefix" yaml:"prefix"`
	Padding int    `json:"padding" yaml:"padding"`
	Total   int    `json:"total" yaml:"total"`
}

Result holds the computed next ID and related metadata.

func Calculate

func Calculate(ids []string) Result

Calculate determines the next available ID from a list of existing IDs. It finds the maximum numeric suffix and returns max+1, preserving any common prefix and zero-padding.

Jump to

Keyboard shortcuts

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