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

id

package
v1.9.3 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package id defines TypeID-based identity types for all Dispatch entities.

Every entity in Dispatch uses a single ID struct with a prefix that identifies the entity type. IDs are K-sortable (UUIDv7-based), globally unique, and URL-safe in the format "prefix_suffix".

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AnyID

type AnyID = ID

AnyID is a type alias that accepts any valid prefix.

type ArtifactID

type ArtifactID = ID

ArtifactID is a type-safe identifier for artifacts (prefix: "art").

type CheckpointID

type CheckpointID = ID

CheckpointID is a type-safe identifier for workflow checkpoints (prefix: "ckpt").

type CronID

type CronID = ID

CronID is a type-safe identifier for cron entries (prefix: "cron").

type DLQID

type DLQID = ID

DLQID is a type-safe identifier for dead letter queue entries (prefix: "dlq").

type EventID

type EventID = ID

EventID is a type-safe identifier for events (prefix: "evt").

type ID

type ID struct {
	// contains filtered or unexported fields
}

ID is the primary identifier type for all Dispatch entities. It wraps a TypeID providing a prefix-qualified, globally unique, sortable, URL-safe identifier in the format "prefix_suffix".

var Nil ID

Nil is the zero-value ID.

func MustParse

func MustParse(s string) ID

MustParse is like Parse but panics on error. Use for hardcoded ID values.

func MustParseWithPrefix

func MustParseWithPrefix(s string, expected Prefix) ID

MustParseWithPrefix is like ParseWithPrefix but panics on error.

func New

func New(prefix Prefix) ID

New generates a new globally unique ID with the given prefix. It panics if prefix is not a valid TypeID prefix (programming error).

func NewArtifactID

func NewArtifactID() ID

NewArtifactID generates a new unique artifact ID.

func NewCheckpointID

func NewCheckpointID() ID

NewCheckpointID generates a new unique checkpoint ID.

func NewCronID

func NewCronID() ID

NewCronID generates a new unique cron ID.

func NewDLQID

func NewDLQID() ID

NewDLQID generates a new unique DLQ ID.

func NewEventID

func NewEventID() ID

NewEventID generates a new unique event ID.

func NewJobID

func NewJobID() ID

NewJobID generates a new unique job ID.

func NewRunID

func NewRunID() ID

NewRunID generates a new unique run ID.

func NewUsageID

func NewUsageID() ID

NewUsageID generates a new unique usage record ID.

func NewWorkerID

func NewWorkerID() ID

NewWorkerID generates a new unique worker ID.

func NewWorkflowID

func NewWorkflowID() ID

NewWorkflowID generates a new unique workflow ID.

func Parse

func Parse(s string) (ID, error)

Parse parses a TypeID string (e.g., "job_01h2xcejqtf2nbrexx3vqjhp41") into an ID. Returns an error if the string is not valid.

func ParseAny

func ParseAny(s string) (ID, error)

ParseAny parses a string into an ID without type checking the prefix.

func ParseArtifactID

func ParseArtifactID(s string) (ID, error)

ParseArtifactID parses a string and validates the "art" prefix.

func ParseCheckpointID

func ParseCheckpointID(s string) (ID, error)

ParseCheckpointID parses a string and validates the "ckpt" prefix.

func ParseCronID

func ParseCronID(s string) (ID, error)

ParseCronID parses a string and validates the "cron" prefix.

func ParseDLQID

func ParseDLQID(s string) (ID, error)

ParseDLQID parses a string and validates the "dlq" prefix.

func ParseEventID

func ParseEventID(s string) (ID, error)

ParseEventID parses a string and validates the "evt" prefix.

func ParseJobID

func ParseJobID(s string) (ID, error)

ParseJobID parses a string and validates the "job" prefix.

func ParseRunID

func ParseRunID(s string) (ID, error)

ParseRunID parses a string and validates the "wfrun" prefix.

func ParseUsageID

func ParseUsageID(s string) (ID, error)

ParseUsageID parses a string and validates the "use" prefix.

func ParseWithPrefix

func ParseWithPrefix(s string, expected Prefix) (ID, error)

ParseWithPrefix parses a TypeID string and validates that its prefix matches the expected value.

func ParseWorkerID

func ParseWorkerID(s string) (ID, error)

ParseWorkerID parses a string and validates the "wkr" prefix.

func ParseWorkflowID

func ParseWorkflowID(s string) (ID, error)

ParseWorkflowID parses a string and validates the "wf" prefix.

func (ID) IsNil

func (i ID) IsNil() bool

IsNil reports whether this ID is the zero value.

func (ID) MarshalBSONValue

func (i ID) MarshalBSONValue() (bsonType byte, data []byte, err error)

MarshalBSONValue satisfies bson.ValueMarshaler (mongo-driver v2) so the ID is stored as a BSON string instead of an opaque struct. No bson import needed because Go uses structural typing for interface satisfaction.

func (ID) MarshalText

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

MarshalText implements encoding.TextMarshaler.

func (ID) Prefix

func (i ID) Prefix() Prefix

Prefix returns the prefix component of this ID.

func (*ID) Scan

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

Scan implements sql.Scanner for database retrieval.

func (ID) String

func (i ID) String() string

String returns the full TypeID string representation (prefix_suffix). Returns an empty string for the Nil ID.

func (ID) Time

func (i ID) Time() time.Time

Time returns the creation instant carried in the ID's UUIDv7 timestamp, at millisecond precision. The nil ID returns the zero time.

Stores that keep IDs in an unordered structure (redis sets) use it to score an ordered index, which is why it lives here and not in a store.

func (*ID) UnmarshalBSONValue

func (i *ID) UnmarshalBSONValue(t byte, data []byte) error

UnmarshalBSONValue satisfies bson.ValueUnmarshaler (mongo-driver v2).

func (*ID) UnmarshalText

func (i *ID) UnmarshalText(data []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

func (ID) Value

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

Value implements driver.Valuer for database storage. Returns nil for the Nil ID so that optional foreign key columns store NULL.

type JobID

type JobID = ID

JobID is a type-safe identifier for jobs (prefix: "job").

type Prefix

type Prefix string

Prefix identifies the entity type encoded in a TypeID.

const (
	PrefixJob        Prefix = "job"
	PrefixWorkflow   Prefix = "wf"
	PrefixRun        Prefix = "wfrun"
	PrefixCheckpoint Prefix = "ckpt"
	PrefixCron       Prefix = "cron"
	PrefixDLQ        Prefix = "dlq"
	PrefixEvent      Prefix = "evt"
	PrefixWorker     Prefix = "wkr"
	PrefixArtifact   Prefix = "art"
	PrefixUsage      Prefix = "use"
)

Prefix constants for all Dispatch entity types.

type RunID

type RunID = ID

RunID is a type-safe identifier for workflow runs (prefix: "wfrun").

type UsageID

type UsageID = ID

UsageID is a type-safe identifier for usage records (prefix: "use").

type WorkerID

type WorkerID = ID

WorkerID is a type-safe identifier for workers (prefix: "wkr").

type WorkflowID

type WorkflowID = ID

WorkflowID is a type-safe identifier for workflow definitions (prefix: "wf").

Jump to

Keyboard shortcuts

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