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 ¶
- Variables
- type ID
- func (id ID) Compare(other ID) int
- func (id ID) Format(f fmt.State, verb rune)
- func (id ID) IsZero() bool
- func (id ID) MarshalJSON() ([]byte, error)
- func (id ID) MarshalText() ([]byte, error)
- func (id *ID) Scan(src any) error
- func (id ID) String() string
- func (id ID) Time() time.Time
- func (id *ID) UnmarshalJSON(b []byte) error
- func (id *ID) UnmarshalText(b []byte) error
- func (id ID) Value() (driver.Value, error)
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 ¶
Parse reads the canonical form (lower or upper case). "" is Nil. Anything else, a bare number included, is ErrNotAnID.
func (ID) Format ¶
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) MarshalJSON ¶
MarshalJSON is the canonical string, or null for Nil.
func (ID) MarshalText ¶
MarshalText and UnmarshalText make an ID a JSON map key and a flag value.
func (*ID) UnmarshalJSON ¶
UnmarshalJSON reads a canonical string or null.
func (*ID) UnmarshalText ¶
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. |