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

id

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

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

Every entity in Chronicle 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 ArchiveID

type ArchiveID = ID

ArchiveID is a type-safe identifier for archives (prefix: "archive").

type AuditID

type AuditID = ID

AuditID is a type-safe identifier for audit events (prefix: "audit").

type CheckpointID

type CheckpointID = ID

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

type ErasureID

type ErasureID = ID

ErasureID is a type-safe identifier for erasure requests (prefix: "erasure").

type ID

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

ID is the primary identifier type for all Chronicle 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 NewArchiveID

func NewArchiveID() ID

NewArchiveID generates a new unique archive ID.

func NewAuditID

func NewAuditID() ID

NewAuditID generates a new unique audit event ID.

func NewCheckpointID

func NewCheckpointID() ID

NewCheckpointID generates a new unique checkpoint ID.

func NewErasureID

func NewErasureID() ID

NewErasureID generates a new unique erasure ID.

func NewPluginID

func NewPluginID() ID

NewPluginID generates a new unique plugin ID.

func NewPolicyID

func NewPolicyID() ID

NewPolicyID generates a new unique retention policy ID.

func NewReportID

func NewReportID() ID

NewReportID generates a new unique report ID.

func NewStreamID

func NewStreamID() ID

NewStreamID generates a new unique stream ID.

func Parse

func Parse(s string) (ID, error)

Parse parses a TypeID string (e.g., "audit_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 ParseArchiveID

func ParseArchiveID(s string) (ID, error)

ParseArchiveID parses a string and validates the "archive" prefix.

func ParseAuditID

func ParseAuditID(s string) (ID, error)

ParseAuditID parses a string and validates the "audit" prefix.

func ParseCheckpointID

func ParseCheckpointID(s string) (ID, error)

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

func ParseErasureID

func ParseErasureID(s string) (ID, error)

ParseErasureID parses a string and validates the "erasure" prefix.

func ParsePluginID

func ParsePluginID(s string) (ID, error)

ParsePluginID parses a string and validates the "plugin" prefix.

func ParsePolicyID

func ParsePolicyID(s string) (ID, error)

ParsePolicyID parses a string and validates the "retpol" prefix.

func ParseReportID

func ParseReportID(s string) (ID, error)

ParseReportID parses a string and validates the "report" prefix.

func ParseStreamID

func ParseStreamID(s string) (ID, error)

ParseStreamID parses a string and validates the "stream" 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 (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) 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 PluginID

type PluginID = ID

PluginID is a type-safe identifier for plugins (prefix: "plugin").

type PolicyID

type PolicyID = ID

PolicyID is a type-safe identifier for retention policies (prefix: "retpol").

type Prefix

type Prefix string

Prefix identifies the entity type encoded in a TypeID.

const (
	PrefixAudit      Prefix = "audit"
	PrefixStream     Prefix = "stream"
	PrefixErasure    Prefix = "erasure"
	PrefixReport     Prefix = "report"
	PrefixPolicy     Prefix = "retpol"
	PrefixArchive    Prefix = "archive"
	PrefixPlugin     Prefix = "plugin"
	PrefixCheckpoint Prefix = "ckpt"
)

Prefix constants for all Chronicle entity types.

type ReportID

type ReportID = ID

ReportID is a type-safe identifier for reports (prefix: "report").

type StreamID

type StreamID = ID

StreamID is a type-safe identifier for streams (prefix: "stream").

Jump to

Keyboard shortcuts

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