nextid

package
v0.0.0-...-5f22abe Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2026 License: MIT Imports: 6 Imported by: 0

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 truncated to that length. 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