Identity (TypeID)
How Relay uses prefix-qualified, globally unique identifiers for every entity.
Every entity in Relay has a TypeID. TypeIDs are globally unique, sortable, URL-safe identifiers built on UUIDv7 with a human-readable prefix that tells you what kind of entity you're looking at.
A TypeID looks like this:
evt_01h455vb4pex5vsknk084sn02qThe evt prefix identifies this as an event. The suffix is a base32-encoded UUIDv7 that encodes creation time, so IDs sort chronologically.
The id package
The id package wraps the TypeID Go library (v2) with a single ID struct. All entity types share the same struct -- the prefix distinguishes them.
Creating IDs
import "github.com/xraph/relay/id"
eventTypeID := id.New(id.PrefixEventType) // evtype_01h455vb...
endpointID := id.New(id.PrefixEndpoint) // ep_01h455vb...
eventID := id.New(id.PrefixEvent) // evt_01h455vb...Convenience constructors: id.NewEventTypeID(), id.NewEndpointID(), id.NewEventID(), id.NewDeliveryID(), id.NewDLQID(), id.NewSecretID().
Parsing IDs
parsed, err := id.Parse("evt_01h455vb4pex5vsknk084sn02q")
parsed, err := id.ParseWithPrefix("evt_01h455vb...", id.PrefixEvent) // validates prefix
parsed, err := id.ParseEventID("evt_01h455vb...") // convenienceNil ID
var empty id.ID
empty.IsNil() // true
empty.String() // ""
id.Nil.IsNil() // trueDatabase storage
id.ID implements Scanner and driver.Valuer. Stores as a string, returns NULL for nil IDs.
JSON serialization
id.ID implements TextMarshaler and TextUnmarshaler. Nil IDs serialize as empty strings.
Prefix reference
| Constant | Prefix | Entity |
|---|---|---|
id.PrefixEventType | evtype | Event type |
id.PrefixEndpoint | ep | Webhook endpoint |
id.PrefixEvent | evt | Event |
id.PrefixDelivery | del | Delivery attempt |
id.PrefixDLQ | dlq | Dead letter queue entry |
id.PrefixSecret | whsec | Signing secret |