id

package
v0.0.2-alpha Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package id generates identifiers for hex applications.

One consistent surface for the three ID formats we reach for most:

  • UUID v4 — random 128-bit ID, no time component
  • UUID v7 — time-sortable 128-bit ID (RFC 9562)
  • ULID — 128-bit time-sortable, Crockford base32
  • KSUID — 27-char time-sortable

Prefer UUID v7 or ULID for new tables — they are sortable by insertion time, which speeds up index scans without giving up global uniqueness.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func KSUID

func KSUID() string

KSUID returns a 27-character KSUID.

func ULID

func ULID() string

ULID returns a Crockford base32-encoded ULID.

func UUIDv4

func UUIDv4() string

UUIDv4 returns a random UUID v4 as a string.

func UUIDv7

func UUIDv7() string

UUIDv7 returns a time-sortable UUID v7 (RFC 9562).

Types

type Kind

type Kind int

Kind names an identifier scheme.

const (
	// KindUnknown means Parse could not identify the format.
	KindUnknown Kind = iota
	// KindUUID covers UUID v4 and v7 — same string shape.
	KindUUID
	// KindULID is a Crockford base32-encoded 26-char ID.
	KindULID
	// KindKSUID is a 27-char segment.io ID.
	KindKSUID
)

func Parse

func Parse(s string) Kind

Parse attempts to identify and parse an ID string, returning the detected kind. Useful for logging or defensive validation. Returns KindUnknown when no format matches.

func (Kind) String

func (k Kind) String() string

String returns the human name for k.

Jump to

Keyboard shortcuts

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