ids

package
v1.0.0-rc.7 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package ids is a record's identity: a UUIDv7 minted when the record is made (design/decisions/mergeable-forge-data.md). It is the only identity keys, references, URLs and payloads use; people see display numbers and names instead. The package knows nothing of AppTown.

The zero ID is "no record": SQL NULL and JSON null, so an absent reference is never a magic value.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotAnID = errors.New("not a record id")

ErrNotAnID: text that is not a canonical UUID.

Functions

This section is empty.

Types

type ID

type ID [16]byte

ID is a UUID, by convention a version 7 minted here.

var Nil ID

Nil is the zero ID: no record.

func New

func New(now time.Time) ID

New mints a UUIDv7 at now (AppTown's clock): 48 bits of Unix milliseconds, a 12-bit counter, then random bits. IDs minted by one process are strictly increasing; a clock stepped back is held at the last millisecond seen, so order never reverses within the process.

func Parse

func Parse(s string) (ID, error)

Parse reads the canonical form (lower or upper case). "" is Nil. Anything else, a bare number included, is ErrNotAnID.

func (ID) Compare

func (id ID) Compare(other ID) int

Compare orders IDs by their bytes: for v7 IDs, mint order. -1, 0 or +1.

func (ID) Format

func (id ID) Format(f fmt.State, verb rune)

Format prints the canonical form for every verb, so a format string written for an integer id (%d, %v) prints the UUID rather than sixteen numbers.

func (ID) IsZero

func (id ID) IsZero() bool

IsZero reports whether id is Nil.

func (ID) MarshalJSON

func (id ID) MarshalJSON() ([]byte, error)

MarshalJSON is the canonical string, or null for Nil.

func (ID) MarshalText

func (id ID) MarshalText() ([]byte, error)

MarshalText and UnmarshalText make an ID a JSON map key and a flag value.

func (*ID) Scan

func (id *ID) Scan(src any) error

Scan reads NULL as Nil, and a uuid column's text or bytes.

func (ID) String

func (id ID) String() string

String is the canonical form, xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx; Nil is "".

func (ID) Time

func (id ID) Time() time.Time

Time is the millisecond a v7 ID was minted at.

func (*ID) UnmarshalJSON

func (id *ID) UnmarshalJSON(b []byte) error

UnmarshalJSON reads a canonical string or null.

func (*ID) UnmarshalText

func (id *ID) UnmarshalText(b []byte) error

func (ID) Value

func (id ID) Value() (driver.Value, error)

Value stores Nil as NULL and anything else as its text form, which Postgres reads into a uuid column.

Directories

Path Synopsis
Package idstest gives tests readable, stable record ids, so a test can still say "change 7" where a fixture needs an id it did not mint.
Package idstest gives tests readable, stable record ids, so a test can still say "change 7" where a fixture needs an id it did not mint.

Jump to

Keyboard shortcuts

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