Help us shape the future of Go! Take the 2026 Go Developer Survey

ulid

package
v0.71.0 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package ulid is part of the GoFastr harness.

See docs/harness-architecture.md for the architecture this package implements.

Package ulid implements a minimal pure-stdlib ULID generator.

ULIDs are 128-bit identifiers encoded as 26-character Crockford base32 strings. They are lexicographically sortable by creation time and URL-safe. The first 48 bits are the millisecond timestamp; the remaining 80 bits are random.

This implementation is intentionally minimal, it covers what the harness needs (generate, parse, validate) and nothing else. Spec: https://github.com/ulid/spec

Index

Constants

View Source
const Length = 26

Length is the number of characters in a ULID string.

Variables

This section is empty.

Functions

func IsValid

func IsValid(s string) bool

IsValid reports whether s is a syntactically valid ULID string.

func MustNewPrefixed

func MustNewPrefixed(prefix string) string

MustNewPrefixed returns a new prefixed ULID string and panics on error.

func NewPrefixed

func NewPrefixed(prefix string) (string, error)

NewPrefixed returns a new prefixed ULID string like "sess_01H...". The prefix is lower-cased and joined with "_".

Types

type ULID

type ULID [16]byte

ULID is a 128-bit identifier.

func FromSeed

func FromSeed(seed []byte) ULID

FromSeed returns a deterministic ULID derived from the given 16-byte seed (typically a SHA-256 prefix). Used for branch ID rewriting where two clients branching the same boundary must produce the same new IDs.

func MustNew

func MustNew() ULID

MustNew returns a new ULID and panics on error. Only the random source can fail; in practice this never happens.

func New

func New() (ULID, error)

New returns a new ULID with the current timestamp and a random suffix.

func NewAt

func NewAt(t time.Time) (ULID, error)

NewAt returns a new ULID with the given timestamp and a random suffix.

func Parse

func Parse(s string) (ULID, error)

Parse decodes a 26-character Crockford base32 string into a ULID.

func SplitPrefixed

func SplitPrefixed(s string) (prefix string, u ULID, err error)

SplitPrefixed splits a prefixed ULID into (prefix, ulid). The ULID portion is validated. Returns an error on malformed input.

func (ULID) String

func (u ULID) String() string

String encodes the ULID as a 26-character Crockford base32 string.

The 128-bit value is encoded as 26 base32 characters (130 bits with the top 2 bits zero). The first character covers the top 3 bits of the timestamp; the remaining 25 characters cover 125 bits, totaling 128 bits + 2 leading zero bits.

func (ULID) Time

func (u ULID) Time() time.Time

Time returns the timestamp embedded in the ULID.

Jump to

Keyboard shortcuts

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